May 10, 2011 at 8:26 am
Why would you use where 1=1
I have this
update statment
UPDATE JOURN SET T5 = '49999'
FROM JOURN X
WHERE 1=1AND AM.Posting IN ('L','S')
Thank you
May 10, 2011 at 9:02 am
Most people do this when they build dyanmic sql from a search form with many possible search options.
You start with 1 = 1 (100% of the rows)... then you start adding the filters
and
and
and
It makes the code shorter because you don't have to remember if the first where has been added.
May 10, 2011 at 9:08 am
It can be used any time a logical condition is needed that should always be true.
while 1=1
begin
if SomeLogicalCondition
break -- to exit while loop
end
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply