[dba-SQLServer] Counts of value ranges

jwcolby jwcolby at colbyconsulting.com
Thu Apr 24 09:02:21 CDT 2008


I just wrote a query in Access:

SELECT qrptBilling.Bill, [Bill]<10 AS LT10, [Bill]<20 And [Bill]>=10 AS 
GTE10LT20 FROM qrptBilling;

When I try to do the same thing in SQL Server it promptly wraps the 
[Bill]<10 in single quotes and treats it as a string:

SELECT qrptBilling.Bill, '[Bill]<10' AS LT10, '[Bill]<20' And 
'[Bill]>=10' AS GTE10LT20 FROM qrptBilling;

Obviously not what I am trying to get at.  So how does one accomplish 
turning a value comparison into a boolean in SQL Server?

jwcolby wrote:
> Guys,
> 
> Is there a way in SQL to get counts of records in value ranges:
> 
> $2,000,000+
> $1 - $1.99M
> $750K - $999K
> $500K - $749K
> $400K - $499K
> $300K - $399K
> $200K - $299K
> $100K - $199K
> <$100K

-- 
John W. Colby
www.ColbyConsulting.com



More information about the dba-SQLServer mailing list