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 |
ozandalkiran
Starting Member
13 Posts |
Posted - 2013-02-05 : 03:19:58
|
hi i wanna query we have two tables salesall and stations.we have to make sum of the daily sales. group by product, stations, saledate but i dont want to add sumution which sales typeid = 18 how can i do please help me SELECT convert(varchar(10),[SaleBegin],104) as SaleBegin ,S.[EPDKLicenseCode] ,[ProductID] ,sum([Volume]) as TotalVolume FROM [PUMPOMAT_HO].[dbo].[SalesAll] inner join stations S on S.RID = SalesAll.StationID where (SaleBegin >='20130201' and SaleBegin < '20130205') and (ProductID= 22 or ProductID=23 ) group by S.[EPDKLicenseCode],SaleBegin,Volume,Total,ProductID |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-02-05 : 03:24:31
|
sounds like this to meSELECT [SaleBegin],S.[EPDKLicenseCode],[ProductID],sum(case when typeid=18 then 0 else [Volume] end) as TotalVolumeFROM [PUMPOMAT_HO].[dbo].[SalesAll]inner join stations SonS.RID = SalesAll.StationIDwhere (SaleBegin >='20130201' and SaleBegin < '20130205') and (ProductID= 22 or ProductID=23 )group by S.[EPDKLicenseCode],SaleBegin,ProductID please dont convert dates to varchar for formatting, do it at your front end applicationIf above didnt give you what you were looking for, post some sample data and your expected output------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
ozandalkiran
Starting Member
13 Posts |
Posted - 2013-02-05 : 03:57:04
|
thanks.but i had extra problem when in group by date, for exampe should be shown 01.01.2013 22 140 01.01.2013 22 260 it is wrong should be 01.01.2013 400 how can i solve this problemquote: Originally posted by visakh16 sounds like this to meSELECT [SaleBegin],S.[EPDKLicenseCode],[ProductID],sum(case when typeid=18 then 0 else [Volume] end) as TotalVolumeFROM [PUMPOMAT_HO].[dbo].[SalesAll]inner join stations SonS.RID = SalesAll.StationIDwhere (SaleBegin >='20130201' and SaleBegin < '20130205') and (ProductID= 22 or ProductID=23 )group by S.[EPDKLicenseCode],SaleBegin,ProductID please dont convert dates to varchar for formatting, do it at your front end applicationIf above didnt give you what you were looking for, post some sample data and your expected output------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
|
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
|
|
|
|
|