Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Getting stats on repartition
Message
 
 
To
11/01/2011 16:52:13
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2008
Application:
Web
Miscellaneous
Thread ID:
01495766
Message ID:
01495771
Views:
37
This message has been marked as a message which has helped to the initial question of the thread.
>A SQL like this will get the status but will omit the status having no entry:
>
>
>SELECT ExportDestination.Title,ExportStatus.Title_E,Temp.CountRecord
>FROM
>(SELECT Export.NoExportStatus,Export.NoExportDestination,COUNT(*) AS CountRecord
> FROM Export (NOLOCK)
> GROUP BY Export.NoExportStatus,Export.NoExportDestination) Temp
>INNER JOIN ExportDestination ON Temp.NoExportDestination=ExportDestination.Numero
>INNER JOIN ExportStatus ON Temp.NoExportStatus=ExportStatus.Numero
>
You need to start from ExportStatus table and LEFT JOIN with the rest of your query.
SELECT ExportDestination.Title,ExportStatus.Title_E,COALESCE(Temp.CountRecord,0) as CountRecord
FROM
(SELECT Export.NoExportStatus,Export.NoExportDestination,COUNT(*) AS CountRecord
 FROM Export (NOLOCK)
 GROUP BY Export.NoExportStatus,Export.NoExportDestination) Temp
INNER JOIN ExportDestination ON Temp.NoExportDestination=ExportDestination.Numero
RIGHT JOIN ExportStatus ON Temp.NoExportStatus=ExportStatus.Numero
-- use RIGHT JOIN to get all statuses from ExportStatus.
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform