Display values for the whole month - Sundar

04-Jan-08 06:13:00
Dear Sir,

My values in the table is given below.

sys_line_Num	item	date		qty
1		1	01/01/2008	100
2		1	02/01/2008	200
3		1	03/01/2008	300
4		1	05/01/2008	400

I want to display the values in the report in the following way for the
whole month

item	day1	day2	day3	day4	day5	day7 ........
1	100	200	300	0	400

Kindly help us how to display the above result.

regards
SUNDARA MURTHY
reply
 
 

Display values for the whole month - Tom Moreau

04-Jan-08 07:00:58
Try:

select
item
,    sum (case when datepart (dd, [date]) = 1 then qty else 0 end) as day1
,    sum (case when datepart (dd, [date]) = 2 then qty else 0 end) as day2
,    sum (case when datepart (dd, [date]) = 3 then qty else 0 end) as day3
...
from
MyTable
group by
item
--
Tom

----------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
SQL Server MVP
Toronto, ON   Canada
https://mvp.support.microsoft.com/profile/Tom.Moreau


Dear Sir,

My values in the table is given below.

sys_line_Num item date qty
1 1 01/01/2008 100
2 1 02/01/2008 200
3 1 03/01/2008 300
4 1 05/01/2008 400

I want to display the values in the report in the following way for the
whole month

item day1 day2 day3 day4 day5 day7 ........
1 100 200 300 0 400

Kindly help us how to display the above result.

regards
SUNDARA MURTHY
reply
 

Display values for the whole month - Sundar

04-Jan-08 07:16:01
thanks a lot.
reply
 

Display values for the whole month - Sundar

04-Jan-08 07:17:01
one more issue that i want to sum the qty for a particular week
reply
 

Display values for the whole month - Tom Moreau

04-Jan-08 07:57:16
Then you can add a WHERE clause to filter that:

select
item
,    sum (case when datepart (dd, [date]) = 1 then qty else 0 end) as day1
,    sum (case when datepart (dd, [date]) = 2 then qty else 0 end) as day2
,    sum (case when datepart (dd, [date]) = 3 then qty else 0 end) as day3
...
from
MyTable
where
date    >= '20080108'
and  date    <  '20080115'
group by
item


--
Tom

----------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
SQL Server MVP
Toronto, ON   Canada
https://mvp.support.microsoft.com/profile/Tom.Moreau


one more issue that i want to sum the qty for a particular week
reply
 
Append data with BCP
promotion
Silverlight    WPF    WCF    WWF    LINQ   
JavaScript    AJAX    ASP.NET    XAML   
C#    VB.NET    VB 6.0    GDI+    IIS    XML   
.NET Generics    Anonymous Methods    Delegate   
Visual Studio .NET    Expression Blend    Virus   
Windows Vista    Windows XP    Windows Update   
Windows 2003 Server    Windows 2008 Server   
SQL Server    Microsoft Excel    Microsoft Word   
SharePoint    BizTalk    Virtual Earth   
.NET Compact Framework    Web Service   

"Everything" RSS / ATOM Feed Parser
How to send and receive messages through message queuing in .Net
How to Read text file as database
SQL Server 2005 Paging Performance Tip
Display code of web page.
Fully Scalable Excel File Importer class for .net using Microsoft Jet driver
Generic Chart Color Manager class that can be used for any charts
Helper class to style the infragistics wingrid
Using Reflection to detemine as Assembly Info in and out.
Helper class to play with Window (Owners and position)
Resolving displayname from the culture using the XmlLanguage and LanguageSpecificStringDictionary class