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

后端 未结 7 1364
情话喂你
情话喂你 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:40

    Something like this:

    CREATE FUNCTION [dbo].[Age](@set VARCHAR(10))  
    RETURNS @Players TABLE
    (
        playerId INT,
        Name VARCHAR(50)
    ) 
    AS  
    BEGIN 
    
        INSERT INTO @Players
        SELECT playerId, Name
        FROM player 
        WHERE CASE WHEN @set = 'tall' AND height > 180 THEN 1
        WHEN @set = 'average' AND height BETWEEN 155 AND 180 THEN 1
        WHEN @set = 'low' AND height < 155 THEN 1 ELSE 0 END = 1
    
        RETURN
    END
    

提交回复
热议问题