Sql Server - How to have Multiple IF Condition in Table Valued Functions

 
How to have Multiple IF Condition in Table Valued Functions
 
CREATE FUNCTION  dbo.testTVF
(
                @Parameter1  as varchar(2) ,
                @Parameter2 as integer
)
RETURNS @mytable table
(             
                CountOfRecords int
)
As
 
begin
 
                if (@Parameter1  ='LP' )
                                Insert into @mytable (CountOfRecords)
                                Select count(*) as CountOfRecords from TestTable  where FieldOne is null
                                and Field2= @Parameter2
 
                else if (@Parameter1  ='FT')
                                Insert into @mytable (CountOfRecords)
                                Select count(*) as CountOfRecords from  TestTable where FieldOne is null
                                                and Field2 = @Parameter2
                               
 
                else if (@Parameter1  ='SN')
                                Insert into @mytable (CountOfRecords)
                                Select count(*) as CountOfRecords from TestTable  where FieldOne is null
                                                                and Field2= @Parameter2
                RETURN
end
 

Comments

Popular posts from this blog

Shared / Static Class in vb.net/C#

Xamarin Forms : PopUp Page with RG.Plugins.Popup

Text was truncated or one or more characters had no match in the target code page.". (SQL Server Import and Export Wizard)