ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Using IF EXISTS inside CASE block in SQL (https://www.excelbanter.com/excel-programming/409968-using-if-exists-inside-case-block-sql.html)

[email protected]

Using IF EXISTS inside CASE block in SQL
 
Hi

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

Thanks
Mayur

Bob Phillips

Using IF EXISTS inside CASE block in SQL
 
IF EXISTS, is what exists?

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

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

wrote in message
...
Hi

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

Thanks
Mayur




Rob Bovey

Using IF EXISTS inside CASE block in SQL
 
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,
CASE
WHEN EXISTS (SELECT ReportID
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
http://www.appspro.com/

* Take your Excel development skills to the next level.
* Professional Excel Development
http://www.appspro.com/Books/Books.htm

wrote in message
...
Hi

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

Thanks
Mayur





All times are GMT +1. The time now is 09:40 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com