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
 General SQL Server Forums
 New to SQL Server Programming
 Help understanding this line of code

Author  Topic 

smithani
Starting Member

42 Posts

Posted - 2007-08-16 : 15:40:38
case @namesflag when 3 then 1
else case @namesflag when 2 then names.new else names.old
end
end=1

I understand what it is doing for the second part when @namesflag=2
, but what does end=1 mean
Can somebody please explain it to me.
Thanks

ashley.sql
Constraint Violating Yak Guru

299 Posts

Posted - 2007-08-16 : 15:44:24
is end=1 not giving you syntax error

Ashley Rhodes
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-08-16 : 15:45:55
end = 1 compares the result of the case statement to 1.
you have this case in your where clause, no?

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

smithani
Starting Member

42 Posts

Posted - 2007-08-16 : 15:46:25
No, it compiles fine
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-08-16 : 15:46:29
You better post full query.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

smithani
Starting Member

42 Posts

Posted - 2007-08-16 : 15:56:29
spirit1,
Yes, this was written by smebody else in foxpro view, I am trying to understand it,
To answer your question yes it is in a where clause.

so it compare the result of case, so when case is 3 then 1 end =1 is true, so goes thru the case again, can you please explain.
Thanks a million
Go to Top of Page

smithani
Starting Member

42 Posts

Posted - 2007-08-16 : 15:56:33
spirit1,
Yes, this was written by smebody else in foxpro view, I am trying to understand it,
To answer your question yes it is in a where clause.

so it compare the result of case, so when case is 3 then 1 end =1 is true, so goes thru the case again, can you please explain.
Thanks a million
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2007-08-16 : 16:05:31
we are gonna need the whole query (as stated before) and the DDL of the tables and the declartion of the local variables



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

smithani
Starting Member

42 Posts

Posted - 2007-08-16 : 16:19:13
I think i understood it, thanks spirit1 for your earlier answer to my question.
case @namesflag when 3 then 1
else case @namesflag when 2 then names.new else names.old
end
end=1

when @namesflag='3' then it sets to 1 and end =1 compares result to 1 , since it is true, exits,
Thanks for your input spirit1
Go to Top of Page

smithani
Starting Member

42 Posts

Posted - 2007-08-16 : 16:19:17
I think i understood it, thanks spirit1 for your earlier answer to my question.
case @namesflag when 3 then 1
else case @namesflag when 2 then names.new else names.old
end
end=1

when @namesflag='3' then it sets to 1 and end =1 compares result to 1 , since it is true, exits,
Thanks for your input spirit1
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-08-16 : 16:23:21
No need for nested cases either

case when @namesflag = 3 then 1
when @namesflag = 2 then names.new
else names.old
end=1



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-08-16 : 16:24:33
WHERE @NamesFlag = 3 ÒR (@NamesFlag = 2 AND Names.New = 1) OR Names.Old = 1



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

smithani
Starting Member

42 Posts

Posted - 2007-08-16 : 16:32:42
wow, so it sets the values to 1, that's what end=1 does, would never have guessed it.Thanks Peso
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-08-17 : 04:40:58
no it does ot set any values.
it COMPARES them!


_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page
   

- Advertisement -