Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 diff between "Where 1=0" and "Where 1=1"

Author  Topic 

joseln
Starting Member

11 Posts

Posted - 2007-11-26 : 04:50:38
Hi

i am fresher in IT, pls kindly let me know the difference between

"Where 1=0" and "Where 1=1" which we use in SQL Query

Thanks

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-11-26 : 04:52:25
"1=0" will return FALSE
"1=1" will return TRUE

when you used that in the WHERE clause, the statement will always be TRUE (1=1) or FALSE(1=0)


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-11-26 : 04:54:25
Its simple comparison logic. 1=0 will always return False and 1=1 always returns True. Normally Where 1=0 is used to extract just table structure like column names from table to create its replica. 1=1 might be used to generate an uncondition while loop.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-11-26 : 04:55:35
moved from article discussion

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-11-26 : 05:17:13
To retreive table structure, you can also use

Select top 0 * from table_name

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

georgev
Posting Yak Master

122 Posts

Posted - 2007-11-26 : 05:54:45
Or indeed
[CODE]
SET FMTONLY ON
SELECT * FROM tableName
SET FMTONLY OFF
[/CODE]


George
<3Engaged!
Go to Top of Page
   

- Advertisement -