SQL If Statement

Posted on 2014-08-20
Last Modified: 2014-09-05

I have a stored procedure which includes this clause:

    if (select *** FROM ***…..)!='L'

This works okay but I need to change it so that it checks for two values; basically execute return if the result of the select statement is not L or is not S
I’ve tried a couple of approaches but none seem to work? Any suggestions please?
Question by:andyw27
    LVL 21

    Accepted Solution

    if (select *** FROM ***…..) not in ('L', 'S')
    LVL 44

    Expert Comment

    by:Vitor Montalvão
    Your code it's too short. Could you show more of the Select statement?

    I would say that you should have a WHERE clause, so will be more easy. Example:
    SELECT Field1, Field2, ..., FieldN
    FROM table
    WHERE FieldX NOT IN ('L', 'S')

    Open in new window

    LVL 14

    Expert Comment

    by:Vikas Garg

    You can try this one

    If(select count(*) from DimAccount where field not in ('L','S')) > 0
    LVL 11

    Expert Comment

    (	SELECT	*
    	FROM	SomeTable
    	WHERE	SomeField NOT IN ('L', 'S')
    )	RETURN

    Open in new window


    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
    Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now