user56737
user56737

Reputation:

Transact SQL: selecting a boolean expression

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

Upvotes: 4

Views: 1391

Answers (1)

Chris McCall
Chris McCall

Reputation: 10397

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

Bitwise AND operator in Transact-SQL

Upvotes: 7

Related Questions