SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 How to get Below T-SQL qury Output..?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

bhushan_juare
Starting Member

45 Posts

Posted - 03/09/2013 :  03:20:53  Show Profile  Reply with Quote
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

India
52249 Posts

Posted - 03/09/2013 :  03:28:52  Show Profile  Reply with Quote

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


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

Go to Top of Page

bhushan_juare
Starting Member

45 Posts

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

visakh16
Very Important crosS Applying yaK Herder

India
52249 Posts

Posted - 03/13/2013 :  01:40:30  Show Profile  Reply with Quote
welcome

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

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.09 seconds. Powered By: Snitz Forums 2000