sql server - t-SQL Aggregate Logic -
lets have table id , bit column. execute query returns number of rows (for example id>5). want have , aggregate operation across results of bit column. have figured out workaround, it's not pretty:
select case when count(id) = sum(cast(istrue int)) 1 else 0 end aretrue table id > 5
what i'm doing here, since there no aggregate function multiply results, practically comparing total number of records sum of integer representation of bit column. if they're equal, there no 'falses', works , operation between them.
an or max column, pretty straightforward.
the problem particularly ugly , should killed fire. there elegant, proper, way this?
you achieve using variable store calculation, example:
declare @result bit = 1 select @result = @result & istrue table id > 5
Comments
Post a Comment