开发者

if else nesting in stored procedures

I have a stored procedure with if-else statements. i have a scenario where i need a need if else statement inside else statement. i have done this in c# 开发者_Go百科but i need it in sql server since i'm pretty much new to stored procedures. lemme provide a sample snippet for u ppl.

create procedure [dbo].[usp_getstore_details](@input varchar(100))
as 
begin
    declare @out varchar(100)
    declare @result int

    if(LEN(@input)=2)
        begin
          --select  statement here.
        end
    else if (@input like '%[0-9]%')
        begin
          --select statement here 
        end
    else 
        begin
            set @result=(len(@input) - len(replace(@input, ',', '') )
            if(@result>1)
                begin
                  --select statement here 
                end
            else
                begin
                  --select statement here
                end
        end
end

Thanks in advance for ur help


CREATE PROCEDURE [dbo].[usp_getstore_details]
@input VARCHAR(100)
AS  
BEGIN 
    DECLARE @out VARCHAR(100) 
    DECLARE @result INT 

    IF LEN(@input) = 2 
    BEGIN 
        --select  statement here. 
    END 
    ELSE IF @input LIKE '%[0-9]%' 
    BEGIN 
        --select statement here  
    END 
    ELSE  
    BEGIN 
        SET @result = LEN(@input) - LEN(REPLACE(@input, ',', '')) 
        IF @result > 1
        BEGIN 
            --select statement here  
        END 
        ELSE 
        BEGIN 
            --select statement here 
        END 
    END 
END 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜