Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Nov 12, 2012 07:20 PM by techgeeksquared
Member
28 Points
42 Posts
Nov 09, 2012 04:35 PM|LINK
Is there a better way to do this?
If @preferred__code_1 in (#,#) or @preferred__code_2 in (#,#) or @preferred__code_3 in (#,#) BEGIN ... Logically it would be like this: If @preferred__code_1 or @preferred__code_2 or @preferred__code_3 in (#,#) BEGIN ...
Thank you for your help.
Star
7625 Points
1454 Posts
Nov 10, 2012 10:12 AM|LINK
optimized way is,
if CHARINDEX('#,#',@preferred__code_1) > 0 or CHARINDEX('#,#',@preferred__code_2) > 0 or CHARINDEX('#,#',@preferred__code_3) > 0
Contributor
2378 Points
393 Posts
Nov 12, 2012 10:11 AM|LINK
techgeeksquared Logically it would be like this: If @preferred__code_1 or @preferred__code_2 or @preferred__code_3 in (#,#)
Since you are using a OR condition, why not concatenate and then check if the "#,#" exists in concatenated string like below:
IF (CHARINDEX('#,#', ISNULL(@preferred__code_1, '') + ISNULL(@preferred__code_2, '') + ISNULL(@preferred__code_3, '')) > 0) BEGIN SELECT 1 END
Nov 12, 2012 07:20 PM|LINK
Yes, I think this might work. Thank you for your help.
techgeeksqua...
Member
28 Points
42 Posts
Better way to use variables
Nov 09, 2012 04:35 PM|LINK
Is there a better way to do this?
Thank you for your help.
santosh.jagd...
Star
7625 Points
1454 Posts
Re: Better way to use variables
Nov 10, 2012 10:12 AM|LINK
optimized way is,
if CHARINDEX('#,#',@preferred__code_1) > 0 or CHARINDEX('#,#',@preferred__code_2) > 0 or CHARINDEX('#,#',@preferred__code_3) > 0MCP
tgyoga
Contributor
2378 Points
393 Posts
Re: Better way to use variables
Nov 12, 2012 10:11 AM|LINK
Since you are using a OR condition, why not concatenate and then check if the "#,#" exists in concatenated string like below:
IF (CHARINDEX('#,#', ISNULL(@preferred__code_1, '') + ISNULL(@preferred__code_2, '') + ISNULL(@preferred__code_3, '')) > 0) BEGIN SELECT 1 ENDYoga
techgeeksqua...
Member
28 Points
42 Posts
Re: Better way to use variables
Nov 12, 2012 07:20 PM|LINK
Yes, I think this might work. Thank you for your help.