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 2000 Forums
 Transact-SQL (2000)
 Where 0=1?

Author  Topic 

yonabout
Posting Yak Master

112 Posts

Posted - 2010-10-07 : 05:16:21
I'm debugging an old stored procedure, and there's a section in it that goes something like this:
select a, b, c 
into #totals
from a
join b on a.a = b.a
where 0=1


what does the "Where 0 = 1" bit do?

I've also seen other selection criteria with "Where 1=1" after it.

I'm assuming that "Where 0 = 1" equates to false, and "Where 1=1" equates to true, but if that's right, what is true or false?


Cheers,

Yonabout

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2010-10-07 : 05:19:04
It is a simple trick to create an empty temp table with same number of columns and format as in the select query.

Harsh Athalye
http://www.letsgeek.net/
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2010-10-07 : 05:44:21
other tricks for the same things are SELECT TOP 0 x, y, z INTO foo FROM....

Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page

yonabout
Posting Yak Master

112 Posts

Posted - 2010-10-07 : 06:03:55
OK, Thanks.

Is "Where 1=1" used to do the same thing?

Cheers,

Yonabout
Go to Top of Page

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2010-10-07 : 06:06:41
quote:
Originally posted by yonabout

OK, Thanks.

Is "Where 1=1" used to do the same thing?

Cheers,

Yonabout



Where 1 = 0 will create the other table with same structure (not index or pk) and the table will be empty

Where 1 = 1 will create the other table with same structure (not index or pk) and the table will also have data of base table.

Regards,
Bohra

I am here to learn from Masters and help new bees in learning.
Go to Top of Page

yonabout
Posting Yak Master

112 Posts

Posted - 2010-10-07 : 06:27:40
Cool.

Thanks for your help

Cheers,

Yonabout
Go to Top of Page

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2010-10-07 : 06:58:36
quote:
Originally posted by yonabout

Cool.

Thanks for your help

Cheers,

Yonabout



You are welcome

I am here to learn from Masters and help new bees in learning.
Go to Top of Page
   

- Advertisement -