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.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 FUNCTION RELATED QUERRY

Author  Topic 

kiranmurali
Yak Posting Veteran

55 Posts

Posted - 2010-07-14 : 01:58:25
how to use if then else condition in function in SQL SERVER 2008?
pls give some sample examples.



thanks in advance
Kiran

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-07-14 : 02:12:40
no diff from using it in stored procedure

create function fn_test
(
@val int
)
returns varchar(10)
as
begin
declare @result varchar(10)

if @val = 1
begin
select @result = 'TRUE'
end
else
begin
select @result = 'FALSE'
end
return @result
end
go

select dbo.fn_test(1), dbo.fn_test(2)



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -