Transact SQL: selecting a boolean expression

sql, sql-server, t-sql

Solution

SELECT TOP 1 ReportInvoked & EmailSent AS ReportSent FROM tblReportInvoker WHERE WebUserId = 12345

Bitwise AND operator in Transact-SQL

Problem

Query: ``` SELECT TOP 1 ReportInvoked , EmailSent FROM tblReportInvoker WHERE WebUserId = 12345 ``` This gives me two bit values. What I really want is a scalar result that is the logical AND of these two values. Is this possible? This seems like it would be easy but I'm not finding a syntax that will work. Edit: Of course the flaw in my clever plan is that it will be true if both processes fail, so revised query to: ``` SELECT TOP 1 (ReportInvoked & EmailSent) & (1 & ReportInvoked) AS 'ReportSent' FROM tblReportInvoker WHERE WebUserId = 12345 ```

Original source