Question : SQL Select query with Case when creating a frequency distribution

I am having difficulty with the correct syntax for a string for SQL select which will create a frequency distribution:-

sSQLString = "SELECT CASE WHEN datalength(Request) < 400 THEN ""Up to 400"" ELSE ""> 400"" END, COUNT(*) AS Count_  FROM dbo.qryStatsRequests WHERE Request IS NOT NULL GROUP BY CASE WHEN datalength(Request) < 400 THEN ""Up to 400"" ELSE ""> 400"" END"

is used in the command db_cmd.CommandText = sSQLString to produce a recordset. This error results: "Invalid column name 'Up to 400'."

Answer : SQL Select query with Case when creating a frequency distribution

Sorry, didn't see that the shru code might be wrong there. Tss, tsss, getting old this days ...


1:
sSQLString = "select data_length, count(*) from (SELECT CASE WHEN datalength(Request) < 400 THEN 'Up to 400' ELSE '> 400' END as data_length FROM dbo.qryStatsRequests WHERE Request IS NOT NULL ) a GROUP BY a.data_length"
Random Solutions  
 
programming4us programming4us