Showing posts with label perform. Show all posts
Showing posts with label perform. Show all posts

Monday, March 26, 2012

Help with sp_executesql and return parameter

I am trying to use dynamic sql with a return parameter, but with limited success. I am using WebMatrix, vb.net and MSDE to perform this routine. Can someone please clue me in. I have read two fine articles by <a href='http://www.algonet.se/~sommar/dyn-search.html>Erland Sommarskog</a> on dynamic sql using sp_executesql, as well as the somewhat opaque article by Microsoft (262499) on the subject.

While there may be other ways to accomplish this task, I am interested in making it work with dynamic SQL. In production, there will be over 20 parameters coming from the vb.net to the SQL, being driven from user input. Then those same variables will be used to actually retrieve the records to a datagrid.

So with a tip of the cap to Rod Serling, I submit this small code and SQL for your consideration from my Twilight Zone:


Public Function totalrecordsbysql(list as arraylist) as integer
dim RetVal as new integer
dim querystring as string

Dim cn As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("Indiafriend"))
Dim cmd As SqlCommand = New SqlCommand("SimpleDynProfileCount", cn)
cmd.commandtype = commandtype.storedprocedure

dim mydr as SqlDataReader

cmd.Parameters.add("@.TotalRecords",SqlDbType.int).direction=ParameterDirection.Output
cmd.Parameters.add("@.age",sqldbtype.int).value = 18

cn.Open()

try
mydr=cmd.executereader()
catch e as sqlexception
dim err as sqlerror
dim strErrorString as string

for each err in e.Errors
strErrorString += "SqlError: #" & err.Number.ToString () & vbCRLF + err.Message
trace.write("sqlexception",strErrorString)
Next

finally

RetVal = cmd.parameters("@.TotalRecords").value

end try

Return RetVal
cn.close()
End Function


Now here is the stored procedure:

CREATE PROCEDURE SimpleDynProfileCount

@.age int,
@.TotalRecords int output

AS

Declare @.sql nvarchar(4000),
@.paramlist nvarchar(4000)

select @.sql = 'select @.xTotalRecords = count(*) from profile where 1 = 1 '

// RAISERROR(@.sql, 16, 1)

IF @.age > 0
Select @.sql = @.sql + ' AND age > @.xage '

Select @.paramlist = '@.xage int, @.xTotalRecords int output'

Execute sp_executesql @.sql,@.paramlist,@.age,@.xTotalRecords = @.TotalRecords output

select @.TotalRecords
GO


Please note the commented RAISERROR statement. If I uncomment this statement, I will get a return value of 11 records. If I leave it out, I get zero records.
The data is the database should return 11 records, based on the criteria of age > 11Your code works fine for me in Query Analyzer -- with one exception. I needed to change the double forward slashes (//) to double dashes (--) in front of the RAISERROR.

You might also place a SET NOCOUNT ON at the top of your stored procedure. This will suppress the information "xx items selected" messages and will avoid having them returned inadvertently as a resultset.

Terri|||That's what is so strange: I don't receive error messages, just the wrong answer (zero). The double dashes are just artistic license: I didn't remember the comment tag. I just eliminate the line, altogether, in production.|||Try adding SET NOCOUNT ON after your AS at the top of the stored procedure.

Terri|||I have added the statement, but the results are the same. Works fine with the RAISERROR statement, but returns zero without the statement.

I don't want to just leave the RAISERROR statement active. It will come back to haunt me later.

rod|||I have resolved the syntax.

I made a mistake in the vb.net when I used a datareader to retrieve the output value!

Instead of:


mydr=cmd.executereader()

the syntax should be:

cmd.executeNonQuery()

Using this syntax I removed from the Stored Procedure, the RAISERROR statement and the last SELECT @.totalrecords.

After doing all that, everything worked as expected.

-rod

Wednesday, March 21, 2012

Help with Relational Division

I am trying to create a matrix of counts to help identify our data holdings.
Thanks to Joe Celko I now know I need to perform relational division to find
datasets that match the criteria set up in a secondary table.
I'd be happy to initially just get the counts for each category, as I could
pass the "DSType" parameter in on the fly.
Problem is I can't figure out how from the "Plane/Hanger" example how to
form the relational division query to come up with the counts. Or even a
view listing the datasets that match each "Category"s "Topic" criteria.
There are 4 main tables involved:
-Datasets that we provide information on.
-Types of data that they hold (Regional, Historical, Global, etc.)
-Topics that describe the datasets (Ocean, Carbon, Sea Level, etc.)
-GOOS Matrix that lists Categories that we want to correlate the datasets to
The SQL script to create the tables and insert data into them is at:
http://oceanic.cms.udel.edu/matrix/..._Tables.sql.txt
A PDF of the relationships between the tables is at:
http://oceanic.cms.udel.edu/matrix/..._GOOSMatrix.pdf
And a PDF of the desired matrix view is at:
http://oceanic.cms.udel.edu/matrix/...trix_Output.pdf
TIA,
D
--
"If Pro is the opposite of Con, does that mean that Congress is the opposite
of Progress?"
--GallegherDoes this help? (using Joes's example):
CREATE TABLE PilotSkills (pilot CHAR(15) NOT NULL, plane CHAR(15) NOT
NULL, PRIMARY KEY (pilot, plane));
CREATE TABLE Hangar (plane CHAR(15) NOT NULL PRIMARY KEY);
INSERT INTO PilotSkills (pilot, plane)
SELECT 'Celko', 'Piper Cub' UNION ALL
SELECT 'Higgins', 'B-52 Bomber' UNION ALL
SELECT 'Higgins', 'F-14 Fighter' UNION ALL
SELECT 'Higgins', 'Piper Cub' UNION ALL
SELECT 'Jones', 'B-52 Bomber' UNION ALL
SELECT 'Jones', 'F-14 Fighter' UNION ALL
SELECT 'Smith', 'B-1 Bomber' UNION ALL
SELECT 'Smith', 'B-52 Bomber' UNION ALL
SELECT 'Smith', 'F-14 Fighter' UNION ALL
SELECT 'Wilson', 'B-1 Bomber' UNION ALL
SELECT 'Wilson', 'B-52 Bomber' UNION ALL
SELECT 'Wilson', 'F-14 Fighter' UNION ALL
SELECT 'Wilson', 'F-17 Fighter' ;
INSERT INTO Hangar (plane)
SELECT 'B-1 Bomber' UNION ALL
SELECT 'B-52 Bomber' UNION ALL
SELECT 'F-14 Fighter' ;
SELECT PS1.pilot,
COUNT(PS1.plane) total_skills,
T.total_planes
FROM PilotSkills AS PS1, Hangar AS H1,
(SELECT COUNT(plane) FROM Hangar) AS T(total_planes)
WHERE PS1.plane = H1.plane
GROUP BY PS1.pilot, T.total_planes ;

> The SQL script to create the tables and insert data into them is at:
> http://oceanic.cms.udel.edu/matrix/..._Tables.sql.txt
That's not up to the task in my opinion, which is why I've not used it.
No alternate keys and mostly nullable columns. IDENTITY should not be
the only key of any table and it's very hard to write and verify
queries against such a schema.
David Portas
SQL Server MVP
--

Monday, March 12, 2012

Help with Query

Hi,
Am trying to work out how to perform a query. I have a table which contains
finance cost codes (tblCostCodes). I have another table that contains
Customers and the Cost Codes used by that Customer (tblCustomerCostCodes) -
they are related by the CostCode field. What I want is to be able to extrac
t
the values in the first table only when the values don't appear in the
second. Not sure how to do this.
--
Many thanks in advance for any assistanceSelect * from tblCostCodes C
Where Not Exists (Select * From tblCustomerCostCodes
Where CostCode = C.CostCode )
"Marek" wrote:

> Hi,
> Am trying to work out how to perform a query. I have a table which contai
ns
> finance cost codes (tblCostCodes). I have another table that contains
> Customers and the Cost Codes used by that Customer (tblCustomerCostCodes)
-
> they are related by the CostCode field. What I want is to be able to extr
act
> the values in the first table only when the values don't appear in the
> second. Not sure how to do this.
> --
> Many thanks in advance for any assistance|||That worked a treat - thanks for that
"CBretana" wrote:
> Select * from tblCostCodes C
> Where Not Exists (Select * From tblCustomerCostCodes
> Where CostCode = C.CostCode )
>
> "Marek" wrote:
>|||Yr welcome !
"Marek" wrote:
> That worked a treat - thanks for that
> "CBretana" wrote:
>|||This one should be faster.
Select * from tblCostCodes CC
Left join tblCustomerCostCodes CCC on CCC.CostCode = CC.CostCode
Where CCC.CostCode is null
JN.
"CBretana" <cbretana@.areteIndNOSPAM.com> a crit dans le message de news:
53A0FAE0-26BF-46D8-9CF6-FF195C3FF9A4@.microsoft.com...
> Select * from tblCostCodes C
> Where Not Exists (Select * From tblCustomerCostCodes
> Where CostCode = C.CostCode )
>
> "Marek" wrote:
>|||Why would you say that? I think, internally, the optimizer will do the same
thing, or very close. An experiment I ran with a small resultset, showing
Execution Plan, yielded yours having 51% of the workload and the previous
version at 49%. The important thing to note was that both had two table
scans, more importantly there were deltas here. The NOT EXISTS version had
one with a row count of 5 and one with a row count of 2. (I inserted 5 rows
into CostCodes and 2 rows into CustomerCostCodes.) Your version had one
with a row count of 5, and one with a row count of 10! You also return a
second column for nothing (I suggest you both get out of the habit of
using/recommending SELECT *). So you can imagine where this is going to go
as the size of the tables goes up...
On 3/12/05 6:00 PM, in article OkLMTd1JFHA.732@.TK2MSFTNGP12.phx.gbl,
"Jean-Nicolas BERGER" <j-n.enlevezmoi.berger@.club-internet.fr> wrote:

> This one should be faster.
> Select * from tblCostCodes CC
> Left join tblCustomerCostCodes CCC on CCC.CostCode = CC.CostCode
> Where CCC.CostCode is null
> JN.
> "CBretana" <cbretana@.areteIndNOSPAM.com> a crit dans le message de news:
> 53A0FAE0-26BF-46D8-9CF6-FF195C3FF9A4@.microsoft.com...
>|||I Agree with Aaron,
In General, most of the tme, when I have used showplan to compare using
correlated subquerys with joins, the optimizer laughs at me, and does the
same thing for both... So I generally now opt for the syntax that makes the
logic the most clear...
"Jean-Nicolas BERGER" wrote:

> This one should be faster.
> Select * from tblCostCodes CC
> Left join tblCustomerCostCodes CCC on CCC.CostCode = CC.CostCode
> Where CCC.CostCode is null
> JN.
> "CBretana" <cbretana@.areteIndNOSPAM.com> a écrit dans le message de news:
> 53A0FAE0-26BF-46D8-9CF6-FF195C3FF9A4@.microsoft.com...
>
>|||You're right.
Even for big tables, the execution plan is the same.
Internally, the optimizer thranforms the "if exists" so it looks like a
Join.
(I've tried with tables with 1 000 000 rows)
JN.
"Aaron [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> a crit dans le message de
news: BE58E344.2EF6%ten.xoc@.dnartreb.noraa...
> Why would you say that? I think, internally, the optimizer will do the
> same
> thing, or very close. An experiment I ran with a small resultset, showing
> Execution Plan, yielded yours having 51% of the workload and the previous
> version at 49%. The important thing to note was that both had two table
> scans, more importantly there were deltas here. The NOT EXISTS version had
> one with a row count of 5 and one with a row count of 2. (I inserted 5
> rows
> into CostCodes and 2 rows into CustomerCostCodes.) Your version had one
> with a row count of 5, and one with a row count of 10! You also return a
> second column for nothing (I suggest you both get out of the habit of
> using/recommending SELECT *). So you can imagine where this is going to
> go
> as the size of the tables goes up...
>
> On 3/12/05 6:00 PM, in article OkLMTd1JFHA.732@.TK2MSFTNGP12.phx.gbl,
> "Jean-Nicolas BERGER" <j-n.enlevezmoi.berger@.club-internet.fr> wrote:
>
>

Help with Query

Hi,
I am trying to perform a query that is beyond my knewlegde and was
after little help,
I have two tables in my db, national and CDR. the National table
displays the codes and location for every std code in the UK, the CDR
table displays the information about calls made from people in my
company.
I am trying to reference both tables so that the result display the
location of the dailled numbers, here is the query I have built using
the query tool in SQL but it does not seem to work. could any tell me
where I am going wrong?
SELECT dbo.IpPbxCDR.OriginationNumber, dbo.[National].Location
FROM dbo.[National] CROSS JOIN
dbo.IpPbxCDR
WHERE (dbo.[National].Digits LIKE
'%dbo.IpPbxCDR.OriginationNumber%')
Many Thanks
IanSELECT dbo.IpPbxCDR.OriginationNumber, dbo.[National].Location
FROM dbo.IpPbxCDR LEFT JOIN dbo.[National]
ON (dbo.[National].Digits LIKE
'%dbo.IpPbxCDR.OriginationNumber%')
OR
SELECT dbo.IpPbxCDR.OriginationNumber, dbo.[National].Location
FROM dbo.IpPbxCDR LEFT JOIN dbo.[National]
ON (dbo.[National].Digits = dbo.IpPbxCDR.OriginationNumber)
Dont know why u used Like as you didnt specify the datatypes and the
condition you required...
--
Thanks,
Sree
[Please specify the version of Sql Server as we can save one thread and time
asking back if its 2000 or 2005]
"Crumb" wrote:
> Hi,
> I am trying to perform a query that is beyond my knewlegde and was
> after little help,
> I have two tables in my db, national and CDR. the National table
> displays the codes and location for every std code in the UK, the CDR
> table displays the information about calls made from people in my
> company.
> I am trying to reference both tables so that the result display the
> location of the dailled numbers, here is the query I have built using
> the query tool in SQL but it does not seem to work. could any tell me
> where I am going wrong?
> SELECT dbo.IpPbxCDR.OriginationNumber, dbo.[National].Location
> FROM dbo.[National] CROSS JOIN
> dbo.IpPbxCDR
> WHERE (dbo.[National].Digits LIKE
> '%dbo.IpPbxCDR.OriginationNumber%')
> Many Thanks
> Ian
>|||Thanks Sree,
I don't think I gave enough information as this still did not work!
What I am trying is as follows:
IpPbxCDR Table
OriginationNumber StartTime EndTime
9011839222222 03/03/2006 12:01 03/03/2006 12:12
National Table
Digits Location
0118 Reading
Required Output
OriginationNumber Location StartTime EndTime
9011839222222 Reading 03/03/2006 12:01 03/03/2006 12:12
All Times are DateTimes, the locations and Numbers as Nvarchar
Many Thanks
Ian|||On 5 Mar 2006 14:36:33 -0800, Crumb wrote:
(snip)
>SELECT dbo.IpPbxCDR.OriginationNumber, dbo.[National].Location
>FROM dbo.[National] CROSS JOIN
> dbo.IpPbxCDR
>WHERE (dbo.[National].Digits LIKE
>'%dbo.IpPbxCDR.OriginationNumber%')
Hi Ian,
Without knowledge of how your tables really look (please post CREATE
TABLE and INSERT statements next time - www.aspfaq.com/5006), I can only
offer a wild guess:
SELECT dbo.IpPbxCDR.OriginationNumber, dbo.[National].Location
FROM dbo.[National]
CROSS JOIN dbo.IpPbxCDR
WHERE dbo.[National].Digits LIKE '%'
+ dbo.IpPbxCDR.OriginationNumber
+ '%'
or (technically the same - just a matter of taste which you pick)
SELECT dbo.IpPbxCDR.OriginationNumber, dbo.[National].Location
FROM dbo.[National]
INNER JOIN dbo.IpPbxCDR
ON dbo.[National].Digits LIKE '%'
+ dbo.IpPbxCDR.OriginationNumber
+ '%'
Hugo Kornelis, SQL Server MVP

Help with Query

Hi,

I am trying to perform a query that is beyond my knewlegde and was
after little help,

I have two tables in my db, national and CDR. the National table
displays the codes and location for every std code in the UK, the CDR
table displays the information about calls made from people in my
company.

I am trying to reference both tables so that the result display the
location of the dailled numbers, here is the query I have built using
the query tool in SQL but it does not seem to work. could any tell me
where I am going wrong?

SELECT dbo.IpPbxCDR.OriginationNumber, dbo.[National].Location
FROM dbo.[National] CROSS JOIN
dbo.IpPbxCDR
WHERE (dbo.[National].Digits LIKE
'%dbo.IpPbxCDR.OriginationNumber%')

Many Thanks

IanPlease post your DDL + INSERT statements of sample data + desired results.

--
Tom

----------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinpub.com
..
"Crumb" <rowan.ian@.gmail.com> wrote in message
news:1141597991.414860.283020@.j33g2000cwa.googlegr oups.com...
Hi,

I am trying to perform a query that is beyond my knewlegde and was
after little help,

I have two tables in my db, national and CDR. the National table
displays the codes and location for every std code in the UK, the CDR
table displays the information about calls made from people in my
company.

I am trying to reference both tables so that the result display the
location of the dailled numbers, here is the query I have built using
the query tool in SQL but it does not seem to work. could any tell me
where I am going wrong?

SELECT dbo.IpPbxCDR.OriginationNumber, dbo.[National].Location
FROM dbo.[National] CROSS JOIN
dbo.IpPbxCDR
WHERE (dbo.[National].Digits LIKE
'%dbo.IpPbxCDR.OriginationNumber%')

Many Thanks

Ian|||On 5 Mar 2006 14:33:11 -0800, Crumb wrote:

>Hi,
(snip)

Hi Ian,

Answered in microsoft.public.sqlserver.server.

Please don't post copies of the same question to multiple locations; it
makes it harder for you to keep track of the answers and yields extra
work for those who try to answer.

--
Hugo Kornelis, SQL Server MVP

Friday, March 9, 2012

Help with Query

Hi,
I am trying to perform a query that is beyond my knewlegde and was
after little help,
I have two tables in my db, national and CDR. the National table
displays the codes and location for every std code in the UK, the CDR
table displays the information about calls made from people in my
company.
I am trying to reference both tables so that the result display the
location of the dailled numbers, here is the query I have built using
the query tool in SQL but it does not seem to work. could any tell me
where I am going wrong?
SELECT dbo.IpPbxCDR.OriginationNumber, dbo.[National].Location
FROM dbo.[National] CROSS JOIN
dbo.IpPbxCDR
WHERE (dbo.[National].Digits LIKE
'%dbo.IpPbxCDR.OriginationNumber%')
Many Thanks
Ian
SELECT dbo.IpPbxCDR.OriginationNumber, dbo.[National].Location
FROM dbo.IpPbxCDR LEFT JOIN dbo.[National]
ON (dbo.[National].Digits LIKE
'%dbo.IpPbxCDR.OriginationNumber%')
OR
SELECT dbo.IpPbxCDR.OriginationNumber, dbo.[National].Location
FROM dbo.IpPbxCDR LEFT JOIN dbo.[National]
ON (dbo.[National].Digits = dbo.IpPbxCDR.OriginationNumber)
Dont know why u used Like as you didnt specify the datatypes and the
condition you required...
Thanks,
Sree
[Please specify the version of Sql Server as we can save one thread and time
asking back if its 2000 or 2005]
"Crumb" wrote:

> Hi,
> I am trying to perform a query that is beyond my knewlegde and was
> after little help,
> I have two tables in my db, national and CDR. the National table
> displays the codes and location for every std code in the UK, the CDR
> table displays the information about calls made from people in my
> company.
> I am trying to reference both tables so that the result display the
> location of the dailled numbers, here is the query I have built using
> the query tool in SQL but it does not seem to work. could any tell me
> where I am going wrong?
> SELECT dbo.IpPbxCDR.OriginationNumber, dbo.[National].Location
> FROM dbo.[National] CROSS JOIN
> dbo.IpPbxCDR
> WHERE (dbo.[National].Digits LIKE
> '%dbo.IpPbxCDR.OriginationNumber%')
> Many Thanks
> Ian
>
|||Thanks Sree,
I don't think I gave enough information as this still did not work!
What I am trying is as follows:
IpPbxCDR Table
OriginationNumberStartTime EndTime
901183922222203/03/2006 12:0103/03/2006 12:12
National Table
DigitsLocation
0118Reading
Required Output
OriginationNumberLocationStartTimeEndTime
9011839222222Reading03/03/2006 12:0103/03/2006 12:12
All Times are DateTimes, the locations and Numbers as Nvarchar
Many Thanks
Ian
|||On 5 Mar 2006 14:36:33 -0800, Crumb wrote:
(snip)
>SELECT dbo.IpPbxCDR.OriginationNumber, dbo.[National].Location
>FROM dbo.[National] CROSS JOIN
> dbo.IpPbxCDR
>WHERE (dbo.[National].Digits LIKE
>'%dbo.IpPbxCDR.OriginationNumber%')
Hi Ian,
Without knowledge of how your tables really look (please post CREATE
TABLE and INSERT statements next time - www.aspfaq.com/5006), I can only
offer a wild guess:
SELECT dbo.IpPbxCDR.OriginationNumber, dbo.[National].Location
FROM dbo.[National]
CROSS JOIN dbo.IpPbxCDR
WHERE dbo.[National].Digits LIKE '%'
+ dbo.IpPbxCDR.OriginationNumber
+ '%'
or (technically the same - just a matter of taste which you pick)
SELECT dbo.IpPbxCDR.OriginationNumber, dbo.[National].Location
FROM dbo.[National]
INNER JOIN dbo.IpPbxCDR
ON dbo.[National].Digits LIKE '%'
+ dbo.IpPbxCDR.OriginationNumber
+ '%'
Hugo Kornelis, SQL Server MVP

Help with Query

Hi,
I am trying to perform a query that is beyond my knewlegde and was
after little help,
I have two tables in my db, national and CDR. the National table
displays the codes and location for every std code in the UK, the CDR
table displays the information about calls made from people in my
company.
I am trying to reference both tables so that the result display the
location of the dailled numbers, here is the query I have built using
the query tool in SQL but it does not seem to work. could any tell me
where I am going wrong?
SELECT dbo.IpPbxCDR.OriginationNumber, dbo.[National].Location
FROM dbo.[National] CROSS JOIN
dbo.IpPbxCDR
WHERE (dbo.[National].Digits LIKE
'%dbo.IpPbxCDR.OriginationNumber%')
Many Thanks
IanSELECT dbo.IpPbxCDR.OriginationNumber, dbo.[National].Location
FROM dbo.IpPbxCDR LEFT JOIN dbo.[National]
ON (dbo.[National].Digits LIKE
'%dbo.IpPbxCDR.OriginationNumber%')
OR
SELECT dbo.IpPbxCDR.OriginationNumber, dbo.[National].Location
FROM dbo.IpPbxCDR LEFT JOIN dbo.[National]
ON (dbo.[National].Digits = dbo.IpPbxCDR.OriginationNumber)
Dont know why u used Like as you didnt specify the datatypes and the
condition you required...
Thanks,
Sree
[Please specify the version of Sql Server as we can save one thread and
time
asking back if its 2000 or 2005]
"Crumb" wrote:

> Hi,
> I am trying to perform a query that is beyond my knewlegde and was
> after little help,
> I have two tables in my db, national and CDR. the National table
> displays the codes and location for every std code in the UK, the CDR
> table displays the information about calls made from people in my
> company.
> I am trying to reference both tables so that the result display the
> location of the dailled numbers, here is the query I have built using
> the query tool in SQL but it does not seem to work. could any tell me
> where I am going wrong?
> SELECT dbo.IpPbxCDR.OriginationNumber, dbo.[National].Location
> FROM dbo.[National] CROSS JOIN
> dbo.IpPbxCDR
> WHERE (dbo.[National].Digits LIKE
> '%dbo.IpPbxCDR.OriginationNumber%')
> Many Thanks
> Ian
>|||Thanks Sree,
I don't think I gave enough information as this still did not work!
What I am trying is as follows:
IpPbxCDR Table
OriginationNumber StartTime EndTime
9011839222222 03/03/2006 12:01 03/03/2006 12:12
National Table
Digits Location
0118 Reading
Required Output
OriginationNumber Location StartTime End
Time
9011839222222 Reading 03/03/2006 12:01 03/03/2006 12:12
All Times are DateTimes, the locations and Numbers as Nvarchar
Many Thanks
Ian|||On 5 Mar 2006 14:36:33 -0800, Crumb wrote:
(snip)
>SELECT dbo.IpPbxCDR.OriginationNumber, dbo.[National].Location
>FROM dbo.[National] CROSS JOIN
> dbo.IpPbxCDR
>WHERE (dbo.[National].Digits LIKE
>'%dbo.IpPbxCDR.OriginationNumber%')
Hi Ian,
Without knowledge of how your tables really look (please post CREATE
TABLE and INSERT statements next time - www.aspfaq.com/5006), I can only
offer a wild guess:
SELECT dbo.IpPbxCDR.OriginationNumber, dbo.[National].Location
FROM dbo.[National]
CROSS JOIN dbo.IpPbxCDR
WHERE dbo.[National].Digits LIKE '%'
+ dbo.IpPbxCDR.OriginationNumber
+ '%'
or (technically the same - just a matter of taste which you pick)
SELECT dbo.IpPbxCDR.OriginationNumber, dbo.[National].Location
FROM dbo.[National]
INNER JOIN dbo.IpPbxCDR
ON dbo.[National].Digits LIKE '%'
+ dbo.IpPbxCDR.OriginationNumber
+ '%'
Hugo Kornelis, SQL Server MVP