Nested IF Statements

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • goal2007
    New Member
    • Jul 2007
    • 25

    #1

    Nested IF Statements

    Here is what i am trying to do

    select ID, FName, LName
    if(SUBSTRING(Fi rstName, 1, 4)= 'Mike')
    Begin
    Replace(FirstNa m,'Mike','MikeT est')
    if(SUBSTRING(La stName, 1, 4)= 'Kong')
    Begin
    Replace(LastNam ,'Kong,'KongTes t')
    if(SUBSTRING(Ad dress, 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
  • davef
    New Member
    • Sep 2007
    • 98

    #2
    Originally posted by goal2007
    Here is what i am trying to do

    select ID, FName, LName
    if(SUBSTRING(Fi rstName, 1, 4)= 'Mike')
    Begin
    Replace(FirstNa m,'Mike','MikeT est')
    if(SUBSTRING(La stName, 1, 4)= 'Kong')
    Begin
    Replace(LastNam ,'Kong,'KongTes t')
    if(SUBSTRING(Ad dress, 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.

    Comment

    Working...