| Author |
Topic |
|
nenne
Starting Member
7 Posts |
Posted - 2009-04-20 : 05:07:11
|
| Hi, Can someone help me why i got this result from a queryBesok is a value 1 or 2F1 is between 1 and 4SELECT Besok, F1, COUNT(F1) AS antalFROM mytableGROUP BY ALL F1, BesokORDER BY F1And the result is:Besok F1 antal2 NULL 01 1 02 1 01 2 02 2 01 3 02 3 01 4 02 4 0Why do i get the first row with null. This happens only on my production database, not in my developing envionment.Database is SQL2005Any clue?Lennart |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2009-04-20 : 05:08:40
|
You are BOTH grouping by column F1 and counting the occurencies of column F1. E 12°55'05.63"N 56°04'39.26" |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2009-04-20 : 05:13:17
|
The reason for NULL, is that some record(s) in your production database has NULL for F1 column. E 12°55'05.63"N 56°04'39.26" |
 |
|
|
nenne
Starting Member
7 Posts |
Posted - 2009-04-20 : 05:20:31
|
| Database is empty, as you can see of the result |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2009-04-20 : 05:25:33
|
Table is not empty. If the table were empty you would be an empty resultset back.See this example.DECLARE @Sample TABLE ( Besok INT, F1 INT )-- On empty tableSELECT Besok, F1, COUNT(F1) AS antalFROM @SampleGROUP BY ALL F1, BesokORDER BY F1-- Populate tableINSERT @SampleSELECT 1, 1 UNION ALLSELECT 1, NULL UNION ALLSELECT 2, 0-- On populated tableSELECT Besok, F1, COUNT(F1) AS antalFROM @SampleGROUP BY ALL F1, BesokORDER BY F1 E 12°55'05.63"N 56°04'39.26" |
 |
|
|
nenne
Starting Member
7 Posts |
Posted - 2009-04-20 : 08:13:45
|
| I made a backup of database and restored it on another server. The first row with null value did not show up when using the same query. I belive there must be som konfiguration issue? |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2009-04-20 : 08:19:45
|
Are you sure you are showing us the full query?If you have used WITH CUBE, or WITH ROLLUP on conjunction with GROUP BY, you will get a NULL value as result. E 12°55'05.63"N 56°04'39.26" |
 |
|
|
nenne
Starting Member
7 Posts |
Posted - 2009-04-20 : 08:25:41
|
| I prommise, it's the same query |
 |
|
|
nenne
Starting Member
7 Posts |
Posted - 2009-04-20 : 08:41:54
|
| You got the full query |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-04-20 : 09:10:50
|
| Post some sample data with expected outputMadhivananFailing to plan is Planning to fail |
 |
|
|
nenne
Starting Member
7 Posts |
Posted - 2009-04-20 : 09:35:33
|
| I am expecting all rows except the first, with the null value |
 |
|
|
whitefang
Enterprise-Level Plonker Who's Not Wrong
272 Posts |
Posted - 2009-04-20 : 09:46:25
|
| It's definitely a row with a NULL value in the F1 column. Do this to see if it returns any rowsSELECT F1 FROM mytable WHERE F1 IS NULLIf it does return a row, then you know you have a data integrity issue. |
 |
|
|
nenne
Starting Member
7 Posts |
Posted - 2009-04-20 : 10:23:01
|
| Sorry, but of cause there is a where in the query to filter |
 |
|
|
|