Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can you write a Select Case Statement in Transact SQL 3

Status
Not open for further replies.

SteveRuvolo

Technical User
Nov 26, 2007
6
US
I am trying to use a SELECT CASE Clause in a Tigger and I get an error next to the word CASE

Exampe code:

SELECT CASE @Variable
CASE 'IT'
CODE HERE


CASE 'VEHICLE'
CODE HERE

CASE ELSE

END SELECT
 
Code:
SELECT CASE @Variable
            WHEN 'IT'
                 CODE HERE
            WHEN 'VEHICLE'
                 CODE HERE
       ELSE
                 CODE HERE
       END

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
Microsoft MVP VFP
 
>> Can you write a Select Case Statement in Transact SQL[/!]

Technically, YES, but not the way you are using it.

It appears as though you want to control the flow of execution, in which case, you cannot use case to do it. You'll need to use IF instead.

[tt][blue]
If @Variable = 'IT'
Begin
CODE HERE
End

Else If @Variable = 'VEHICLE'
Begin
Code Here
End
Else
Begin
Code Here
End
[/blue][/tt]



-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top