Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Using IN() and parameter
Message
From
11/02/2013 12:48:00
 
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
01565428
Message ID:
01565731
Views:
53
>>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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform