mardi 4 août 2015

How to get this view to SELECT DISTINCT on first column only in SQL

I am not accustomed to using SQL for View Creation, It's forcing me to use HAVING and GROUP BY, in a standard SQL statement i would use WHERE but apparently that's not allowed. I want to SELECT DISTINCT on dbo.[ShowTex Belgie NV$Item].No_ only. But it is also combining anything i add in GROUP BY it seems. I can't use HAVING on columns unless i include them in GROUP BY. Getting this far has already taken me ages. :/ I just wanted to create a simple WHERE statement ;(

SELECT DISTINCT TOP (100) PERCENT dbo.[ShowTex Belgie NV$Item].No_, SUM(dbo.[ShowTex Belgie NV$Warehouse Entry].Quantity) AS [Quantity Sum]
FROM            dbo.[ShowTex Belgie NV$Item] 
LEFT OUTER JOIN dbo.[ShowTex Belgie NV$Warehouse Entry] ON dbo.[ShowTex Belgie NV$Item].No_ = dbo.[ShowTex Belgie NV$Warehouse Entry].[Item No_]
GROUP BY dbo.[ShowTex Belgie NV$Item].No_, dbo.[ShowTex Belgie NV$Warehouse Entry].[Bin Code]
HAVING        (dbo.[ShowTex Belgie NV$Warehouse Entry].[Bin Code] <> 'SHIPPING') OR
                     (dbo.[ShowTex Belgie NV$Warehouse Entry].[Bin Code] <> 'VERZEND') OR
                     (dbo.[ShowTex Belgie NV$Warehouse Entry].[Bin Code] <> 'WORKSHOP')
ORDER BY dbo.[ShowTex Belgie NV$Item].No_

Using Server Studio Managment 2012 but there doesnt seem to be a hashtag for that.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire