Procedure Problem

  • DEAR Friends,

    I am having a problem with the IF....ELSE condition in the SQL SERVER procedure.

    I am giving the problem part as eg:

    eg:

    IF ((@acno IS NOT NULL) OR (@acno <>'') AND (@actype IS NOT NULL) OR (@actype <>''))

    BEGIN

    PRINT 'hi'

    PRINT ' hello'

    END

    ELSE

    IF ((@acno IS NULL) OR (@acno <>'') AND (@actype IS NOT NULL) OR (@actype <>''))

    BEGIN

    print 'his'

    print 'highness'

    END

    problem

    ======

    WHEN I execute the procedure with inputs as follows

    *********************************************

    exec acno_actype '','CURR'

    *********************************************

    Instead of executing the ELSE condition it executes the IF condition .

    But when I remove the OR condition(ie., acno<>'' ,actype<>'' ) for the IF condition it works perfectly alright.

    Will i be able to know what could be the problem with my IF condition.

    regards

    shown_sunny

  • Try the below code ur missed the bracket for when u using OR:

     

    IF ((@acno IS NOT NULL OR @acno <>'') AND (@actype IS NOT NULL OR @actype <>''))

    BEGIN

    PRINT 'hi'

    PRINT ' hello'

    END

    ELSE

    IF ((@acno IS NULL OR @acno <>'') AND (@actype IS NOT NULL OR @actype <>'')

    BEGIN

    print 'his'

    print 'highness'

    END

  • I also think that there may be a flaw in your @acno logic.  see the below

    IF ((@acno IS NOT NULL OR @acno <>'') AND (@actype IS NOT NULL OR @actype <>''))

    IF ((@acno IS NULL OR @acno = '') AND (@actype IS NOT NULL OR @actype <> '')

    Try this

    IF ISNULL(@acno, '') <> '' AND ISNULL(@actype, '') <> ''

    IF ISNULL(@acno, '') =   '' AND ISNULL(@actype, '') <> ''



    Good Hunting!

    AJ Ahrens


    webmaster@kritter.net

  • Explain (in "pseudo-code", not T-SQL) what you are trying to do.

    Faulty logic that does not work, is all you are showing us.

    Impossible it is, then, to determine your true intent, hm?

  • Dear Friends,

    I got it right by putting the IF...ELSE condition in the following way.

    ********************************************************

    IF ((@acno IS NOT NULL) AND (@acno ''))

    AND ((@actype IS NOT NULL) AND (@actype ''))

    BEGIN

    PRINT 'both parameters filled in'

    END

    ELSE

    IF ((@acno IS NULL) OR (@acno = ''))

    AND ((@actype IS NOT NULL) AND (@actype ''))

    BEGIN

    print 'Only @actype filled in'

    END

    *********************************************************

    Thank u very much for the help.

    regards

    shown_sunny

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply