TSQL - If..Else statement inside Table-Valued Functions - cant go through

后端 未结 7 1366
情话喂你
情话喂你 2021-02-07 02:51

Before posting I have read few articles about developing USD functions, but have not encountered solutions for my problem... which is as follows:

I have a very simple da

7条回答
  •  [愿得一人]
    2021-02-07 03:36

    We can use Table valued function in following way with IF conditions on it.

    CREATE function [dbo].[AA] 
    (
    @abc varchar(10)
    )
    Returns  @mytable table
    (
    supname nvarchar(10), [add] nvarchar(10)
    )
    AS
    begin
    -- lOAD WHATEVER THINGS YOU REQUIRED INTO THIS DYNAMIC TABLE
    if (@abc ='hh')
        insert into @mytable (supname, [add]) values ('hh','gg'+ @abc)
    else
        insert into @mytable (supname, [add]) values ('else','gg'+ @abc)
    return
    end
    

    --select * from [dbo].[AA]('SDAASF')
    

提交回复
热议问题