November 3, 2004 at 9:36 am
Can anybody help with this / I need to know which of a series of WHERE conditions were satisfied in a T-SQL SELECT. For example,
SELECT MyName, MyBirthDate FROM Employees WHERE (MyName LIKE 'David%') OR (MyBirthDate = '10-10-1950') OR ......
Which of the conditions was or were satisfied? Logically-speaking I need to alias the individual conditions and return them with the query items returned. something like : " Davidson , '12-1-1960', True, False "
Any ideas ??
November 3, 2004 at 9:41 am
SELECT MyName, MyBirthDate,
CASE WHEN MyName LIKE 'David%' THEN 1 ELSE 0 END AS NameMatched,
CASE WHEN MyBirthDate = '10-10-1950' THEN 1 ELSE 0 END AS BirthDateMatched,
...
FROM Employees
WHERE (MyName LIKE 'David%') OR (MyBirthDate = '10-10-1950') OR ......
By the way, you should consider using a better date format. The one you're using is ambiguous. The correct non-ambiguous date format for SQL Server is YYYYMMDD. Depending on locale, your current format can mean either DD-MM or MM-DD.
--
Adam Machanic
whoisactive
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply