Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Using IN() and parameter
Message
From
08/02/2013 14:17:10
 
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
01565428
Message ID:
01565522
Views:
36
>>>Hi,
>>>
>>>I have a stored procedure defined like this:
>>>
>>>
ALTER PROCEDURE [dbo].[AirWayBillsSelectByManifestNumbers]
>>>(
>>>	@awb_manifestnumber varchar(100)
>>>)
>>>AS
>>>	SET NOCOUNT ON;
>>>
>>>SELECT [awb_pk]
>>>      ,[awb_keycode]
>>>      ,[awb_manifestdate]
>>>      ,[awb_manifestnumber]
>>>      ,[awb_pieces]
>>>      ,[awb_weight]
>>>      ,[awb_cusfk]
>>>      ,[awb_value]
>>>      ,[awb_freight]
>>>      ,[awb_fuel]
>>>      ,[awb_insurance]
>>>      ,[awb_number]
>>>      ,[awb_shipper]
>>>      ,[awb_description]
>>>      ,[cus_number]
>>>  FROM [dbo].[AirWayBills]
>>>  inner join [dbo].[Customers] on awb_cusfk = cus_PK
>>>	WHERE 
>>>		([awb_manifestnumber] IN (@awb_manifestnumber))
>>>
>>>awb_manifestnumber is an int.
>>>
>>>This works fine if I send in one manifestnumber. However if I send in two like this: '12345,98765' I get an error that the string can't be converted to int. Which of course makes sense.
>>>
>>>I have tried a function to split the string into a table with integers and joining this table, but this is too slow and the reportviewer that I am using times out (apparently).
>>>
>>>This is the function I tried:
>>>
>>>http://www.codeproject.com/Articles/7938/SQL-User-Defined-Function-to-Parse-a-Delimited-Str
>>>
>>>and my SP was:
>>>
>>>
ALTER PROCEDURE [dbo].[AirWayBillsSelectByManifestNumbers]
>>>(
>>>	@awb_manifestnumber varchar(100)
>>>)
>>>AS
>>>	SET NOCOUNT ON;
>>>
>>>if object_id('tepmdb..#awblist',N'U') IS NOT NULL drop table #awblist;
>>>
>>>select int_value
>>>	into #awblist
>>>	from dbo.fn_ParseText2Table(@awb_manifestnumber, ',')
>>>
>>>SELECT [awb_pk]
>>>      ,[awb_keycode]
>>>      ,[awb_manifestdate]
>>>      ,[awb_manifestnumber]
>>>      ,[awb_pieces]
>>>      ,[awb_weight]
>>>      ,[awb_cusfk]
>>>      ,[awb_value]
>>>      ,[awb_freight]
>>>      ,[awb_fuel]
>>>      ,[awb_insurance]
>>>      ,[awb_number]
>>>      ,[awb_shipper]
>>>      ,[awb_description]
>>>      ,[cus_number]
>>>  FROM [dbo].[AirWayBills]
>>>  inner join [dbo].[Customers] on awb_cusfk = cus_PK
>>>  inner join #awblist on #awblist.int_value = awb_manifestnumber
>>>
>>>Any suggestions for alternatives or techniques to speed this up?
>>>
>>>In case it makes a difference, I am calling this from a C# WPF application and I build up the list of manifest numbers from a datagrid.
>>
>>
>>Have you tried this?
>>
>>
ALTER PROCEDURE [dbo].[AirWayBillsSelectByManifestNumbers]
>>(
>>	@awb_manifestnumber varchar(100)
>>)
>>AS
>>	SET NOCOUNT ON;
>>
>>SELECT [awb_pk]
>>      ,[awb_keycode]
>>      ,[awb_manifestdate]
>>      ,[awb_manifestnumber]
>>      ,[awb_pieces]
>>      ,[awb_weight]
>>      ,[awb_cusfk]
>>      ,[awb_value]
>>      ,[awb_freight]
>>      ,[awb_fuel]
>>      ,[awb_insurance]
>>      ,[awb_number]
>>      ,[awb_shipper]
>>      ,[awb_description]
>>      ,[cus_number]
>>  FROM [dbo].[AirWayBills]
>>  inner join [dbo].[Customers] on awb_cusfk = cus_PK
>>	WHERE 
>>		(CHARINDEX(CONVERT(VARCHAR(10), [awb_manifestnumber]), @awb_manifestnumber) > 0)
>
>This is bad and incorrect advice. Don't use such code.

Could you explain why?
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform