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 |
|
work2gs
Starting Member
6 Posts |
Posted - 2009-12-12 : 15:19:50
|
| Hi I define a inline table-valued function as followingALTER FUNCTION [dbo].[GetElt](@Id int)RETURNS TABLEAS RETURN select name from dbo.Elt where Id=@IdIs it possible to use if then else inside ?LikeALTER FUNCTION [dbo].[GetElt](@Id int)RETURNS TABLEAS RETURN If @id=0select name from dbo.Elt elseselect name from dbo.Elt where Id =@IdthanksFred |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-12-12 : 17:10:16
|
Have you tried?You can also do:select name from dbo.Elt where Id =@Id or @Id=0 No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
work2gs
Starting Member
6 Posts |
Posted - 2009-12-13 : 00:50:50
|
| HiThanks a lotis it possible to return all columns (I simplify the select...)ALTER FUNCTION [dbo].[GetGrid](@Id int)RETURNS @Table TABLE(*) ????BEGINIF @catId=0INSERT @Table select * from dbo.EltELSE INSERT @Table select * from dbo.Elt where catId = @catId RETURN |
 |
|
|
cat_jesus
Aged Yak Warrior
547 Posts |
Posted - 2009-12-16 : 15:39:15
|
quote: Originally posted by work2gs HiThanks a lotis it possible to return all columns (I simplify the select...)ALTER FUNCTION [dbo].[GetGrid](@Id int)RETURNS @Table TABLE(*) ????BEGINIF @catId=0INSERT @Table select * from dbo.EltELSE INSERT @Table select * from dbo.Elt where catId = @catId RETURN
how about this?select * from dbo.Elt where catId = coalesce(nullif(@catId ,0),catID)An infinite universe is the ultimate cartesian product. |
 |
|
|
|
|
|