Link to home
Start Free TrialLog in
Avatar of motioneye
motioneyeFlag for Singapore

asked on

Tsql , why use where 1-1 in Tsql query ?

I've seen seen in one of our developed t-sql query code were written with where  1=1 and *****.

I just don't  get it why it must with where 1=1 and then only followed by the actual condition, mind someone here to explain.
SOLUTION
Avatar of Brian Crowe
Brian Crowe
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This is not T-SQL specific by the way, it is true of any SQL.

& It is also just a convention.
It could be 'a' = 'a' that gets used, but 1=1 is way easier to type :)

no points pl.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
(another possibility based on my current gig that I started after the last comment)
Maybe the client has a big honkin' UI that parses dynamic SQL based on user selections, and if the user doesn't select anything relevant then the UI passes a WHERE 1 = 1.   Uglo-riffic!

Thanks for the split, good luck with your project.  -Jim