Using IF EXISTS inside CASE block in SQL

Discussion in 'Microsoft Excel Programming' started by, Apr 25, 2008.

  1. Guest


    Can I use IF EXISTS inside CASE block in SQL (MS SQL SERVER 2000)?
    if yes, how??? if you have example, it will help.

    , Apr 25, 2008
    1. Advertisements

  2. Bob Phillips Guest

    IF EXISTS, is what exists?

    SQL queries the database, so if you want only certain items, you use a WHERE



    (there's no email, no snail mail, but somewhere should be gmail in my addy)
    Bob Phillips, Apr 25, 2008
    1. Advertisements

  3. Rob Bovey Guest

    Hi Mayur,

    Since EXISTS returns a boolean result you can potentially use it in the
    searched form of the T-SQL CASE function. The example shown below, from one
    of my databases, returns a report name and a string indicating whether or
    not a benchmark exists for that report in another table.

    SELECT r.ReportUniqueName,
    FROM ReportBenchmarks
    WHERE ReportID = r.ReportID)
    THEN 'Has Benchmark' ELSE 'No Benchmark' END
    FROM Reports AS r

    I wouldn't say this is the most efficient way to write the query, but it
    does work.

    Rob Bovey, Excel MVP
    Application Professionals

    * Take your Excel development skills to the next level.
    * Professional Excel Development
    Rob Bovey, Apr 25, 2008
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.