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 |
|
XPXJ
Starting Member
4 Posts |
Posted - 2008-08-08 : 21:41:41
|
| What does this syntax check?:CREATE FUNCTION dbo.xyz( @var nvarchar(16))RETURNS intASBEGIN DECLARE @alpha bit DECLARE @ret int SET @alpha = 1 IF @alpha BEGIN SET @ret = 6 END ELSE BEGIN SET @ret = 99 END RETURN @retEND |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-08-09 : 00:09:30
|
[code]DECLARE @alpha bitDECLARE @ret intSET @alpha = 1IF @alphaBEGIN SET @ret = 6ENDELSEBEGIN SET @ret = 99ENDRETURN @retEND[/code]the IF block check for @alpha since @alpha is set to 1 so it will always return value 6 KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-08-09 : 01:52:53
|
you can use a case also to achieve same thingCREATE FUNCTION dbo.xyz(@var nvarchar(16))RETURNS intASBEGINDECLARE @alpha bitDECLARE @ret intSET @alpha = 1SET @ret =CASE WHEN @alpha THEN 6 ELSE 99 ENDRETURN @retEND |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-08-09 : 05:08:46
|
CREATE FUNCTION dbo.xyz(@var nvarchar(16))RETURNS intASBEGINRETURN 6END E 12°55'05.25"N 56°04'39.16" |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-08-09 : 08:37:39
|
| I wonder if T-SQL allows boolean checks like theseIF @alpha....SET @ret =CASE WHEN @alpha THEN 6 ELSE 99 ENDMadhivananFailing to plan is Planning to fail |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-08-09 : 11:42:53
|
quote: Originally posted by madhivanan I wonder if T-SQL allows boolean checks like theseIF @alpha....SET @ret =CASE WHEN @alpha THEN 6 ELSE 99 ENDMadhivananFailing to plan is Planning to fail
yeah...thats true...that was an oversight from my part. it must have been SET @ret =CASE WHEN @alpha=1 THEN 6 ELSE 99 END |
 |
|
|
|
|
|