Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Using IN() and parameter
Message
De
08/02/2013 12:47:23
 
 
À
07/02/2013 16:10:56
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
01565428
Message ID:
01565504
Vues:
43
>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)
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform