Where clause

  • SELECT     Institution, Period

    FROM         Transactions

    WHERE     (0 = 1)

    Could someone please assist? What does the above where clause mean?

  • It pretty much should negate any return set.  This is because 0 will never equal 1.  Similar to if you were to put WHERE 1=1 then it will always return all records since your are guaranteed that 1 equals 1.

  • Some development and front-end tools will generate a:

    select * from <object> where 0 = 1

    for every table and view in a database as a way of cataloging the columns in all the tables and views in a database.

    I sometimes do it myself as part of the process of editing a query.

    The 0 = 1 guarantees no rows will be returned.

  • Thanks for the help!!

  • This will achieve the same without the WHERE clause

    SET FMTONLY ON

    SELECT Institution, Period FROM Transactions

    Far away is close at hand in the images of elsewhere.
    Anon.

  • I've used it many times if I want a quick and easy way to copy the schema of one table to one on another server. Try

    select * from RemoteServer.DB.owner.table1 into LocalTable where 1=0

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply