469,127 Members | 1,425 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,127 developers. It's quick & easy.

Nested IF Statements

Here is what i am trying to do

select ID, FName, LName
if(SUBSTRING(FirstName, 1, 4)= 'Mike')
Begin
Replace(FirstNam,'Mike','MikeTest')
if(SUBSTRING(LastName, 1, 4)= 'Kong')
Begin
Replace(LastNam,'Kong,'KongTest')
if(SUBSTRING(Address, 1, 4)= '1245')
Begin
.........
End
End

end

from dbo.test1Users

When i do that i get this error
Incorrect syntax near the keyword 'from'.

Thank you for your help
Sep 21 '07 #1
1 3099
davef
98
Here is what i am trying to do

select ID, FName, LName
if(SUBSTRING(FirstName, 1, 4)= 'Mike')
Begin
Replace(FirstNam,'Mike','MikeTest')
if(SUBSTRING(LastName, 1, 4)= 'Kong')
Begin
Replace(LastNam,'Kong,'KongTest')
if(SUBSTRING(Address, 1, 4)= '1245')
Begin
.........
End
End

end

from dbo.test1Users

When i do that i get this error
Incorrect syntax near the keyword 'from'.

Thank you for your help
You can't plant the IF clause in the middle of SELECT like that. Consider using CASE construct instead.
Sep 21 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Tcs | last post: by
4 posts views Thread by Profetas | last post: by
10 posts views Thread by nimmi_srivastav | last post: by
39 posts views Thread by slogging_away | last post: by
reply views Thread by Neil Cerutti | last post: by
21 posts views Thread by K Viltersten | last post: by
11 posts views Thread by =?Utf-8?B?anAybXNmdA==?= | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by Mortomer39 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.