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.

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Not sum typeid = 18

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 me

SELECT
[SaleBegin]
,S.[EPDKLicenseCode]
,[ProductID]
,sum(case when typeid=18 then 0 else [Volume] end) 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,ProductID

please dont convert dates to varchar for formatting, do it at your front end application

If above didnt give you what you were looking for, post some sample data and your expected output

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

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 problem

quote:
Originally posted by visakh16

sounds like this to me

SELECT
[SaleBegin]
,S.[EPDKLicenseCode]
,[ProductID]
,sum(case when typeid=18 then 0 else [Volume] end) 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,ProductID

please dont convert dates to varchar for formatting, do it at your front end application

If above didnt give you what you were looking for, post some sample data and your expected output

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/



Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-02-05 : 03:59:35
post some data in understandable format and explain rules for getting your output

see below for guidelines

http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -