if else nesting in stored procedures












0















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# 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










share|improve this question

























  • Apart from one too many ( in this statement set @result=(len(@input) - len(replace(@input, ',', '')) it looks fine to me. Change to set @result=len(@input) - len(replace(@input, ',', '')). Also you can't just have a comment in a begin...end but I guess that you actually have some code in there.

    – Mikael Eriksson
    Sep 29 '11 at 9:49













  • s of course i ve a select statement depends on the condition

    – Csharp_crack
    Sep 29 '11 at 10:36






  • 1





    Ok. So what is the question?

    – Mikael Eriksson
    Sep 29 '11 at 10:58
















0















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# 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










share|improve this question

























  • Apart from one too many ( in this statement set @result=(len(@input) - len(replace(@input, ',', '')) it looks fine to me. Change to set @result=len(@input) - len(replace(@input, ',', '')). Also you can't just have a comment in a begin...end but I guess that you actually have some code in there.

    – Mikael Eriksson
    Sep 29 '11 at 9:49













  • s of course i ve a select statement depends on the condition

    – Csharp_crack
    Sep 29 '11 at 10:36






  • 1





    Ok. So what is the question?

    – Mikael Eriksson
    Sep 29 '11 at 10:58














0












0








0








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# 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










share|improve this question
















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# 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







database sql-server-2008 stored-procedures






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 29 '11 at 10:03









Widor

10.3k62957




10.3k62957










asked Sep 29 '11 at 9:18









Csharp_crackCsharp_crack

961317




961317













  • Apart from one too many ( in this statement set @result=(len(@input) - len(replace(@input, ',', '')) it looks fine to me. Change to set @result=len(@input) - len(replace(@input, ',', '')). Also you can't just have a comment in a begin...end but I guess that you actually have some code in there.

    – Mikael Eriksson
    Sep 29 '11 at 9:49













  • s of course i ve a select statement depends on the condition

    – Csharp_crack
    Sep 29 '11 at 10:36






  • 1





    Ok. So what is the question?

    – Mikael Eriksson
    Sep 29 '11 at 10:58



















  • Apart from one too many ( in this statement set @result=(len(@input) - len(replace(@input, ',', '')) it looks fine to me. Change to set @result=len(@input) - len(replace(@input, ',', '')). Also you can't just have a comment in a begin...end but I guess that you actually have some code in there.

    – Mikael Eriksson
    Sep 29 '11 at 9:49













  • s of course i ve a select statement depends on the condition

    – Csharp_crack
    Sep 29 '11 at 10:36






  • 1





    Ok. So what is the question?

    – Mikael Eriksson
    Sep 29 '11 at 10:58

















Apart from one too many ( in this statement set @result=(len(@input) - len(replace(@input, ',', '')) it looks fine to me. Change to set @result=len(@input) - len(replace(@input, ',', '')). Also you can't just have a comment in a begin...end but I guess that you actually have some code in there.

– Mikael Eriksson
Sep 29 '11 at 9:49







Apart from one too many ( in this statement set @result=(len(@input) - len(replace(@input, ',', '')) it looks fine to me. Change to set @result=len(@input) - len(replace(@input, ',', '')). Also you can't just have a comment in a begin...end but I guess that you actually have some code in there.

– Mikael Eriksson
Sep 29 '11 at 9:49















s of course i ve a select statement depends on the condition

– Csharp_crack
Sep 29 '11 at 10:36





s of course i ve a select statement depends on the condition

– Csharp_crack
Sep 29 '11 at 10:36




1




1





Ok. So what is the question?

– Mikael Eriksson
Sep 29 '11 at 10:58





Ok. So what is the question?

– Mikael Eriksson
Sep 29 '11 at 10:58












1 Answer
1






active

oldest

votes


















0














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





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f7595100%2fif-else-nesting-in-stored-procedures%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    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





    share|improve this answer




























      0














      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





      share|improve this answer


























        0












        0








        0







        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





        share|improve this answer













        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






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Sep 29 '11 at 10:57









        Upendra ChaudhariUpendra Chaudhari

        5,45641841




        5,45641841






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f7595100%2fif-else-nesting-in-stored-procedures%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Bressuire

            Vorschmack

            Quarantine