January 7, 2009 at 4:35 pm
Can't find any explanation behind it. Can anybody please explain me why the results of two select statements are same. I wasn't expecting same results from both of these queries.
CREATE TABLE #tmp (testcol int)
INSERT INTO #tmp values (0)
GO 10
INSERT INTO #tmp values (1)
SELECT * from #tmp
WHERE testcol = ''
SELECT * from #tmp
WHERE testcol = 0
DROP TABLE #tmp
January 7, 2009 at 4:50 pm
anam (1/7/2009)
Can't find any explanation behind it. Can anybody please explain me why the results of two select statements are same. I wasn't expecting same results from both of these queries.
CREATE TABLE #tmp (testcol int)
INSERT INTO #tmp values (0)
GO 10
INSERT INTO #tmp values (1)
SELECT * from #tmp
WHERE testcol = ''
SELECT * from #tmp
WHERE testcol = 0
DROP TABLE #tmp
That is because the empty string ('') casts to 0. Try this: select cast('' as int);
January 7, 2009 at 4:54 pm
anam (1/7/2009)
Can't find any explanation behind it. Can anybody please explain me why the results of two select statements are same. I wasn't expecting same results from both of these queries.
CREATE TABLE #tmp (testcol int)
INSERT INTO #tmp values (0)
GO 10
INSERT INTO #tmp values (1)
SELECT * from #tmp
WHERE testcol = ''
SELECT * from #tmp
WHERE testcol = 0
DROP TABLE #tmp
Interesting ... but I just do the test to be sure that you have right result and from the test it seems thet the value "0" is equaly to = ''
Test:
DECLARE @VAL1 INT
SET @VAL1 = ''
DECLARE @VAL2 INT
SET @VAL2 = 0
IF @VAL1 = @VAL2
PRINT 1
ELSE
PRINT 0
Maybe the others have better explanation!
😎
January 7, 2009 at 4:56 pm
Lynn Pettis (1/7/2009)
anam (1/7/2009)
Can't find any explanation behind it. Can anybody please explain me why the results of two select statements are same. I wasn't expecting same results from both of these queries.
CREATE TABLE #tmp (testcol int)
INSERT INTO #tmp values (0)
GO 10
INSERT INTO #tmp values (1)
SELECT * from #tmp
WHERE testcol = ''
SELECT * from #tmp
WHERE testcol = 0
DROP TABLE #tmp
That is because the empty string ('') casts to 0. Try this: select cast('' as int);
yea, nice explanation Pettis
January 7, 2009 at 5:26 pm
Thanks Lynn.
I think i need another coffee to get me working. i could have figured this out earlier before posting it here.
Cheers
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply