| Author |
Topic |
|
asuni
Yak Posting Veteran
55 Posts |
Posted - 2010-03-24 : 08:20:58
|
| Hi All,what is the similar function for CHOOSE in sqlserver 2005.thanks |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2010-03-24 : 08:24:16
|
What choose function ?What does it do ? KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
asuni
Yak Posting Veteran
55 Posts |
Posted - 2010-03-24 : 08:25:29
|
| CHOOSE (selector number, value 0, value 1, ..., value n)like this any function is there?thanks |
 |
|
|
pk_bohra
Master Smack Fu Yak Hacker
1182 Posts |
Posted - 2010-03-24 : 09:38:31
|
| Hi,Choose in oracle function behaves as follows:Choose(1, "Tech", "on", "the", "Net") would return "Tech" Choose(2, "Tech", "on", "the", "Net") would return "on" Choose(3, "Tech", "on", "the", "Net") would return "the" Choose(4, "Tech", "on", "the", "Net") would return "Net" Choose(5, "Tech", "on", "the", "Net") would return NULL Choose(3.75, "Tech", "on", "the", "Net") would return "the" I don't think that there is any equallant function in SQL Server.Regards,Bohra |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2010-03-24 : 09:58:44
|
there isn't one in SQL Server.What is your input like ? is it a CSV string ? KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
asuni
Yak Posting Veteran
55 Posts |
Posted - 2010-03-25 : 06:54:43
|
| Hi,i created one function for choose as :CREATE FUNCTION dbo.SCHOOSE (@nSelector INT, @n1 INT, @n2 INT) RETURNS INT AS BEGIN DECLARE @RETURN INT IF @nSelector <= 0 set @RETURN = @n1 ELSE set @RETURN = @n2 RETURN @RETURN ENDbut what is happening it is working fine for @nSelector as number.But i need to do as :SELECT SCHOOSE('01-APR-2008' - P_DATE, 0, 1 ) FROM TAB1I have to subtract 2 dates and want to get number in the place of @nSelector.Any help pleasethanks |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2010-03-25 : 07:01:43
|
[code]select schoose ( dateadiff(day, P_DATE, '20080401'), 0, 1)from tab1[/code]why don't you just use CASE statement ?[code]select case when dateadiff(day, P_DATE, '20080401') <= 0 then 0 else 1 endfrom tab1[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
haroon2k9
Constraint Violating Yak Guru
328 Posts |
Posted - 2010-03-25 : 07:02:01
|
| <<I have to subtract 2 dates and want to get number>>LOOK FOR DATEDIFF.SELECT DATEDIFF(DD,GETDATE(),'20100326') |
 |
|
|
asuni
Yak Posting Veteran
55 Posts |
Posted - 2010-03-25 : 07:04:19
|
| OK, thank you very much to all |
 |
|
|
DBA in the making
Aged Yak Warrior
638 Posts |
Posted - 2010-03-25 : 07:06:27
|
quote: Originally posted by khtanwhy don't you just use CASE statement ?
What he said.There are 10 types of people in the world, those that understand binary, and those that don't. |
 |
|
|
|
|
|