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 2008 Forums
 Transact-SQL (2008)
 How to get Below T-SQL qury Output..?

Author  Topic 

bhushan_juare
Starting Member

45 Posts

Posted - 2013-03-09 : 03:20:53
Hi All,
This is the query I have written

DECLARE @FromDate DATETIME
DECLARE @EndDate DATETIME

SET @FromDate = '2013-01-01 00:00:00.000'
SET @EndDate = '2013-02-13 00:00:00.000'

SELECT year(sd.FKDAT) As YEARWISE_DATA,
sg.KUNNR As PARTY,
sg.NAME1 As NAME,
SUM(sd.FKIMG) As QUANTITY,
SUM(sd.NETWR) As VALUE_IN_FC,
SUM(sd.NTGEW) As WEIGHT
FROM
Sales_group sg WITH(NOLOCK)
INNER JOIN
SALES_DATA sd WITH(NOLOCK)
ON
sg.KUNNR = sd.KUNAG
WHERE
sd.FKDAT >= @FromDate
AND
sd.FKDAT <= @EndDate
GROUP By
sd.FKDAT,
sg.KUNNR,
sg.NAME1
ORDER By
1,
sg.KUNNR ASC

Below is the output i am getting,

2013 HA010 ADK 360.000 36988.20 9206.434
2013 HA010 ADK 205.000 31363.80 9299.848
2013 HA018 AGRI 295.000 42646.25 12578.149
2013 HA018 AGRI 119.000 29587.75 8816.112
2013 HA018 AGRI 21.000 10289.65 2882.488
2013 HA018 AGRI 249.000 57764.20 17605.415

Required Output I want

2013 HA010 ADK 565.000 68352.00 18506.31
2013 HA018 AGRI 684.000 140287.85 41882.164

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-03-09 : 03:28:52
[code]
DECLARE @FromDate DATETIME
DECLARE @EndDate DATETIME

SET @FromDate = '2013-01-01 00:00:00.000'
SET @EndDate = '2013-02-13 00:00:00.000'

SELECT year(sd.FKDAT) As YEARWISE_DATA,
sg.KUNNR As PARTY,
sg.NAME1 As NAME,
SUM(sd.FKIMG) As QUANTITY,
SUM(sd.NETWR) As VALUE_IN_FC,
SUM(sd.NTGEW) As WEIGHT
FROM
Sales_group sg WITH(NOLOCK)
INNER JOIN
SALES_DATA sd WITH(NOLOCK)
ON
sg.KUNNR = sd.KUNAG
WHERE
sd.FKDAT >= @FromDate
AND
sd.FKDAT <= @EndDate
GROUP By
YEAR(sd.FKDAT),
sg.KUNNR,
sg.NAME1
ORDER By
1,
sg.KUNNR ASC
[/code]

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

Go to Top of Page

bhushan_juare
Starting Member

45 Posts

Posted - 2013-03-13 : 01:30:05
Hi Visakh,
Thanks for help... with some modifications your logic worked..
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-03-13 : 01:40:30
welcome

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

Go to Top of Page
   

- Advertisement -