Hoi allen,
Ik heb een aantal rijen, die ik wil samenvoegen in een nieuwe tabel tot 1 rij.
Geeft mij de volgende tabel
Dit wil ik groeperen tot:
Dus ik dacht:
Maar dan krijg ik de error The text, ntext, and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator.. Dit treedt op vanwege de kolom Description.
Als ik die uit de select en de group by haal, krijg ik het volgende resultaat.
Hoe krijg ik het nou als gewenst? En dan het liefst incl. de description kolom, omdat die bij sommige records wel gevuld is.
Ik heb een aantal rijen, die ik wil samenvoegen in een nieuwe tabel tot 1 rij.
SQL:
1
2
3
4
5
6
7
8
9
10
11
| SELECT tap.Code, tap.Name, tap.[Description], (CASE tap.Attribute1 WHEN 5 THEN tap.Price END) AS MinValue, (CASE tap.Attribute1 WHEN 6 THEN tap.Price END) AS MiddleValue, (CASE tap.Attribute1 WHEN 7 THEN tap.Price END) AS HighValue, tap.[Type], c.ID AS [CountryID] FROM #TempAvailableProducts tap JOIN Country c ON tap.Country = c.CountryCode COLLATE SQL_Latin1_General_CP1_CI_AS |
Geeft mij de volgende tabel
| Code | Name | Description | MinValue | MiddleValue | HighValue | Type | CountryID |
| 12RM | Dozen Roses | NULL | 50,00 | NULL | NULL | 8 | 36 |
| 12RM | Dozen Roses | NULL | NULL | 75,00 | NULL | 8 | 36 |
| 12RM | Dozen Roses | NULL | NULL | NULL | 100,00 | 8 | 36 |
| 12RM | Dozen Roses | NULL | 50,00 | NULL | NULL | 9 | 36 |
| 12RM | Dozen Roses | NULL | NULL | 75,00 | NULL | 9 | 36 |
| 12RM | Dozen Roses | NULL | NULL | NULL | 100,00 | 9 | 36 |
Dit wil ik groeperen tot:
| Code | Name | Description | MinValue | MiddleValue | HighValue | Type | CountryID |
| 12RM | Dozen Roses | NULL | 50,00 | 75,00 | 100,00 | 8 | 36 |
| 12RM | Dozen Roses | NULL | 50,00 | 75,00 | 100,00 | 9 | 36 |
Dus ik dacht:
SQL:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
| SELECT tap.Code, tap.Name, tap.[Description], (CASE tap.Attribute1 WHEN 5 THEN tap.Price END) AS MinValue, (CASE tap.Attribute1 WHEN 6 THEN tap.Price END) AS MiddleValue, (CASE tap.Attribute1 WHEN 7 THEN tap.Price END) AS HighValue, tap.[Type], c.ID AS [CountryID] FROM #TempAvailableProducts tap JOIN Country c ON tap.Country = c.CountryCode COLLATE SQL_Latin1_General_CP1_CI_AS GROUP BY tap.IntercatCode, tap.Name, tap.[Description], tap.Attribute1, tap.Price, tap.[Type], c.ID |
Maar dan krijg ik de error The text, ntext, and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator.. Dit treedt op vanwege de kolom Description.
Als ik die uit de select en de group by haal, krijg ik het volgende resultaat.
| Code | Name | MinValue | MiddleValue | HighValue | Type | CountryID |
| 12RM | Dozen Roses | 50,00 | NULL | NULL | 8 | 36 |
| 12RM | Dozen Roses | 50,00 | NULL | NULL | 9 | 36 |
| 12RM | Dozen Roses | NULL | 75,00 | NULL | 8 | 36 |
| 12RM | Dozen Roses | NULL | 75,00 | NULL | 9 | 36 |
| 12RM | Dozen Roses | NULL | NULL | 100,00 | 8 | 36 |
| 12RM | Dozen Roses | NULL | NULL | 100,00 | 9 | 36 |
Hoe krijg ik het nou als gewenst? En dan het liefst incl. de description kolom, omdat die bij sommige records wel gevuld is.