Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Using IN() and parameter
Message
 
 
To
07/02/2013 16:10:56
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
01565428
Message ID:
01565429
Views:
53
This message has been marked as the solution to the initial question of the thread.
If you're using SQL Server 2008 and up, can you pass table valued parameter instead?
SQL Server 2008 Table-Valued Parameters and C# Custom Iterators: A Match Made In Heaven!

>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.
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform