| Author |
Topic |
|
sunsanvin
Master Smack Fu Yak Hacker
1274 Posts |
Posted - 2007-10-04 : 03:03:05
|
| Dear all,is there any switch case like we have in C language....in sql server?VinodEven you learn 1%, Learn it with 100% confidence. |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-10-04 : 03:07:40
|
[code]DECLARE @a INT, @b INTSELECT @a = 3, @b = 5-- BeforeSELECT @a, @b-- Magic?SELECT @a = @a ^@b, @b = @a ^@b, @a = @a ^@b-- AfterSELECT @a, @b[/code] E 12°55'05.25"N 56°04'39.16" |
 |
|
|
sunsanvin
Master Smack Fu Yak Hacker
1274 Posts |
Posted - 2007-10-04 : 03:25:06
|
| Dear Peso, can you please explain me claerly........please....VinodEven you learn 1%, Learn it with 100% confidence. |
 |
|
|
sunsanvin
Master Smack Fu Yak Hacker
1274 Posts |
Posted - 2007-10-04 : 03:27:24
|
| actually it is swapping....but i'd like to pass one parameter in switch and based on that, i've to pass values in cases...for matched one, i need the resultVinodEven you learn 1%, Learn it with 100% confidence. |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-10-04 : 03:29:16
|
Do you have an example, please!?Almost 350 posts and still clear as mud. E 12°55'05.25"N 56°04'39.16" |
 |
|
|
sunsanvin
Master Smack Fu Yak Hacker
1274 Posts |
Posted - 2007-10-04 : 03:35:35
|
| Here is the exampleswith (grade){ case 1 : printf('Fall'); break; case 2 : printf('bad'); break; case 3 : printf('good'); break; case 4 : printf('very good'); break; default : printf('you have inputed bad'); break;}VinodEven you learn 1%, Learn it with 100% confidence. |
 |
|
|
sunsanvin
Master Smack Fu Yak Hacker
1274 Posts |
Posted - 2007-10-04 : 03:37:27
|
| i've to pass the value for gradeVinodEven you learn 1%, Learn it with 100% confidence. |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-10-04 : 03:45:52
|
This is EXACTLY the same thing as you posted hereSELECT" rel="nofollow">http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=90448SELECT CASE @Grade WHEN 1 THEN 'Fall.' WHEN 2 THEN 'Bad.' WHEN 3 THEN 'Good.' WHEN 4 THEN 'Very good.' ELSE 'You have inputed bad.' ENDOR DO YOU MEAN SOME PROCEDURAL IF?[code]IF @Grade = 1 BEGIN RAISERROR('Fall.', 16, 1) RETURN ENDELSE IF @Grade = 2 BEGIN RAISERROR('Bad.', 16, 1) RETURN ENDELSE IF @Grade = 3 BEGIN RAISERROR('Good.', 16, 1) RETURN ENDELSE IF @Grade = 4 BEGIN RAISERROR('Very good.', 16, 1) RETURN ENDELSE BEGIN RAISERROR('You have inputed bad.', 16, 1) RETURN END E 12°55'05.25"N 56°04'39.16" |
 |
|
|
jackv
Master Smack Fu Yak Hacker
2179 Posts |
Posted - 2007-10-04 : 03:46:52
|
| There is the CASE command , of which there is the simple and searched variety, e.g SELECT myCol = CASE type WHEN 1 THEN 'Fall' WHEN 2 THEN 'Bad' ELSE '' ENDFROM myTableJack Vamvas--------------------Search IT jobs from multiple sources- http://www.ITjobfeed.com/SQL |
 |
|
|
sunsanvin
Master Smack Fu Yak Hacker
1274 Posts |
Posted - 2007-10-04 : 03:53:36
|
| Sorry for troubling you Peso, but the thing is our team is trying to convert the scripts from sql server to oracle to support our applicatio oracle DB also. there i got the doubt regarding wether switch is there or not...that's why the post.thank you for the great helpVinodEven you learn 1%, Learn it with 100% confidence. |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-10-04 : 03:58:59
|
quote: Originally posted by sunsanvin ...but the thing is our team is trying to convert the scripts from sql server to oracle to support our applicatio oracle DB also.
The scripts you post has nothing to do with Microsoft SQL Server.They look more like C/C++/C# code to me. E 12°55'05.25"N 56°04'39.16" |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-10-04 : 05:16:55
|
quote: Originally posted by Peso
DECLARE @a INT, @b INTSELECT @a = 3, @b = 5-- BeforeSELECT @a, @b-- Magic?SELECT @a = @a ^@b, @b = @a ^@b, @a = @a ^@b-- AfterSELECT @a, @b E 12°55'05.25"N 56°04'39.16"
orDECLARE @a INT, @b INTSELECT @a = 3, @b = 5-- BeforeSELECT @a, @b-- Magic?SELECT @a = @a + @b, @b = @a - @b, @a = @a - @b-- AfterSELECT @a, @b MadhivananFailing to plan is Planning to fail |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-10-04 : 05:19:01
|
quote: Originally posted by sunsanvin Sorry for troubling you Peso, but the thing is our team is trying to convert the scripts from sql server to oracle to support our applicatio oracle DB also. there i got the doubt regarding wether switch is there or not...that's why the post.thank you for the great helpVinodEven you learn 1%, Learn it with 100% confidence.
switch is there in the form of CASE WHEN at both the placesMadhivananFailing to plan is Planning to fail |
 |
|
|
sunsanvin
Master Smack Fu Yak Hacker
1274 Posts |
Posted - 2007-10-04 : 05:29:23
|
| Thank you MadhiVinodEven you learn 1%, Learn it with 100% confidence. |
 |
|
|
|