Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
dorado77
Starting Member
3 Posts |
Posted - 2009-08-10 : 07:34:15
|
| I am making a query on a tableSELECT COUNT(A) AS [COUNT] FROM TABLE It returns [Count]4for a count of four but returns[Count]No rows for a count of 0.I need it to return[Count]0for a count of 0.Any Ideas please ? |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2009-08-10 : 07:37:39
|
Please tell us the whole storyDECLARE @Sample TABLE ( i INT )SELECT COUNT(i) AS [COUNT]FROM @Sample N 56°04'39.26"E 12°55'05.63" |
 |
|
|
dorado77
Starting Member
3 Posts |
Posted - 2009-08-10 : 07:49:44
|
| DECLARE TABLE Records( country varchar(50))insert into Records (US)insert into Records (US)insert into Records (UK)insert into Records (UK)insert into Records (US)select count(country) AS [Count]where country = 'US'returns[Count]3select count(country) AS [Count]where country = 'UK'returns[Count]2Butselect count(country) AS [Count]where country = 'China'returns[Count]I need it to return something like[Count]0with the '0' in there.Cheers ! |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2009-08-10 : 07:55:39
|
Yes. What is it that doesn't work for you?Please tell us the full picture!DECLARE @Records TABLE ( Country VARCHAR(50) )INSERT @RecordsSELECT 'US' UNION ALLSELECT 'US' UNION ALLSELECT 'UK' UNION ALLSELECT 'UK' UNION ALLSELECT 'US'select count(country) AS [Count]from @recordswhere country = 'US'select count(country) AS [Count]from @recordswhere country = 'UK'select count(country) AS [Count]from @recordswhere country = 'China' N 56°04'39.26"E 12°55'05.63" |
 |
|
|
dorado77
Starting Member
3 Posts |
Posted - 2009-08-10 : 08:13:24
|
| select count(country) AS [Count] from @recordswhere country = 'China' (example)returns[Count]I need it to return something like[Count]0with the '0' in there.Cheers ! |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2009-08-10 : 08:29:58
|
Please. Copy and Paste the suggestion above.You will see that for "China" the database engine returns a 0 as resultset.A single column, single row resultset. N 56°04'39.26"E 12°55'05.63" |
 |
|
|
|
|
|