1IF EXISTS (SELECT * FROM tblGLUserAccess WHERE GLUserName ='xxxxxxxx')
2BEGIN
3 SELECT 1
4END
5ELSE
6BEGIN
7 SELECT 2
8END
1Checks for the existence of any record within the subquery, returning true if
2one or more records are returned.
3Example: Lists any dealerships with a deal finance percentage less than 10.
4SELECT dealership_name
5FROM dealerships
6WHERE EXISTS (SELECT deal_name FROM deals WHERE
7dealership_id = deals.dealership_id AND finance_
8percentage < 10);