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.
| Author |
Topic |
|
sharankruthi
Starting Member
22 Posts |
Posted - 2009-07-17 : 02:13:25
|
| BEGIN CASE WHEN (SELECT count(*) from inserted Where seatloc = '') = 1 Then BEGIN print 'waiting list passenger' END WHEN (SELECT count(*) from inserted WHERE seatloc = 0) = 1 Then RAISERROR 10002 'seat 0 does not exist' ROLLBACK TRANSACTION RETURN ELSE print 'Ticket confirmed' ENDWhen i execute above code, i get following error. What is wrong?Error:Msg 156, Level 15, State 1, Procedure status, Line 9Incorrect syntax near the keyword 'CASE'.Msg 102, Level 15, State 1, Procedure status, Line 11Incorrect syntax near '='.Msg 156, Level 15, State 1, Procedure status, Line 15Incorrect syntax near the keyword 'WHEN'.Msg 102, Level 15, State 1, Procedure status, Line 15Incorrect syntax near '='.Msg 156, Level 15, State 1, Procedure status, Line 19Incorrect syntax near the keyword 'ELSE'. |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-07-17 : 02:47:29
|
| TryBEGINIF (SELECT count(*) from inserted Where seatloc = '') = 1 ThenBEGINprint 'waiting list passenger'ENDIF (SELECT count(*) from inserted WHERE seatloc = 0) = 1 ThenRAISERROR 10002 'seat 0 does not exist'ROLLBACK TRANSACTION RETURNELSEprint 'Ticket confirmed'ENDMadhivananFailing to plan is Planning to fail |
 |
|
|
sharankruthi
Starting Member
22 Posts |
Posted - 2009-07-17 : 03:00:37
|
| I knew that.. But why is CASE not working?? |
 |
|
|
rajdaksha
Aged Yak Warrior
595 Posts |
Posted - 2009-07-17 : 03:56:19
|
Hi SELECT CASE WHEN (SELECT COUNT(*) FROM inserted WHERE seatloc = '' ) = 1 THEN 'waiting list passenger' END, CASE WHEN (SELECT COUNT(*) FROM inserted WHERE seatloc = 0 ) = 1 THEN 'seat 0 does not exist' ELSE 'Ticket confirmed' END what madhi is said is right.. no need to use CASE statement..Also refer...http://msdn.microsoft.com/en-us/library/ms181765.aspx-------------------------R.. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-07-17 : 06:28:11
|
quote: Originally posted by sharankruthi I knew that.. But why is CASE not working??
Read about CASE expression in SQL Server help fileMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|