July 16, 2008 at 10:44 am
Thanks
July 16, 2008 at 11:05 am
Jay Murthy (7/16/2008)
A Q. are following 2 queries same or diff and why?declare @val1 varchar(25),@VAL2 varchar(25)
SET @val1 = ''
SET @VAL2 = 'W'
If 'W' In(@val1,@VAL2)
Begin
PRINT 0
End
as long as W exists in one of the @val then you'll print 0
Jay Murthy (7/16/2008)
If Len(@val1) = 1 OrLen(@VAL2) = 1
Begin
PRINT 0
End
Thanks,
Jay Murthy
as long as one of the fields has a char in it it'll print 0
what happens if somehow @val2 = ' ' or @val2 = 'V'
declare @val1 varchar(25),@VAL2 varchar(25)
SET @val1 = ''
SET @VAL2 = ' '
If 'W' In(@val1,@VAL2)
Begin
PRINT 'char'
End
If Len(@val1) = 1 Or
Len(@VAL2) = 1
Begin
PRINT 'len'
End
depends on the point of the exercise
-----------------------------------------------------------------------------------------------------------
"Ya can't make an omelette without breaking just a few eggs" 😉
July 16, 2008 at 11:06 am
They may produce the same results, but they are different. The first query is checking the variable values for an explicit value while the second query is looking at the length of the 2 variable values.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply