Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Using IN() and parameter
Message
De
11/02/2013 12:48:00
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
01565428
Message ID:
01565731
Vues:
52
>>I created a user function to handle this.
>>
>>
>>CREATE FUNCTION [dbo].[isIN] 
>>(
>>	@lcStr varchar(100) ,
>>	@lcList varchar(max)
>>)
>>RETURNS int 
>>AS
>>BEGIN
>>
>>	DECLARE @Test int = 0
>>
>>	if @lcStr = '' or @lcList=''
>>		set @test=1 
>>	else 
>>	if NOT (@lcStr is null or @lcList is null)
>>	begin 
>>		declare @aa int 
>>		set @aa = charindex(','+@lcStr+',',','+@lcList+',')
>>		if @aa>0
>>			set @Test = 1
>>		else 
>>			set @test = 0
>>	end 
>>
>>	RETURN @Test
>>
>>END
>>GO
>>
>>
>>then, in the conditional clause I would
>>
>>
>>WHERE dbo.isIN([awb_manifestnumber], @awb_manifestnumber)>0
>>
>
>This is very bad as you're not using index this way and making query slow by adding scalar UDF into WHERE. I advise you to never use such approach.

While, I would agree. In our case, we are query columns like ZipCodes. There maybe many dozen of them. Besides, the SP are used only once every month or two.

But thanks for the feedback.
Greg Reichert
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform