Click here to Skip to main content
15,906,106 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I want result this...

  Date	    Branch1            Branch2           Branch3            Total	
	    Qty	Value	Qty	Value	Qty	Value	Qty	Value

15-Nov-13	    5	5000	5	5000	5	5000	15	15000
16-Nov-13	    5	5000	5	5000	5	5000	15	15000
17-Nov-13	    5	5000	5	5000	5	5000	15	15000
18-Nov-13	    5	5000	5	5000	5	5000	15	15000
19-Nov-13	    5	5000	5	5000	5	5000	15	15000
20-Nov-13	    5	5000	5	5000	5	5000	15	15000
Posted
Updated 27-Nov-13 7:37am
v2
Comments
Member 10222278 27-Nov-13 0:09am    
Please help any body..
Jörgen Andersson 27-Nov-13 3:27am    
How does your source table look like?
Please use "Improve question" to add that info.
Maciej Los 27-Nov-13 13:39pm    
Good question!
Maciej Los 27-Nov-13 15:24pm    
We can't read in your mind. We can't see your screen. Please, be more specific and provide more details, ex.: sample data and expected output.

Please see solution:
_
_
USE[cpqaAnswers]
GO

CREATE TABLE [cpqa].[tbl_OZ_notevenPivot](
	[Date][datetime],
		[Branch1_Qty][int],
			[Branch1_Value][bigint],
				[Branch2_Qty][int],
					[Branch2_Value][bigint],
						[Branch3_Qty][int],
							[Branch3_Value][bigint]
				)
				
			
INSERT INTO [cpqa].[tbl_OZ_notevenPivot]				
	VALUES('15-Nov-13',5,5000,5,5000,5,5000),
		('16-Nov-13',5,5000,5,5000,5,5000),
		('17-Nov-13',5,5000,5,5000,5,5000),
		('18-Nov-13',5,5000,5,5000,5,5000),
		('19-Nov-13',5,5000,5,5000,5,5000)

First as-is query, given suspected data:
_
_
SELECT * FROM [cpqa].[tbl_OZ_notevenPivot]	

Date	Branch1_Qty	Branch1_Value	Branch2_Qty	Branch2_Value	Branch3_Qty	Branch3_Value
2013-11-15 00:00:00.000	5	5000	5	5000	5	5000
2013-11-16 00:00:00.000	5	5000	5	5000	5	5000
2013-11-17 00:00:00.000	5	5000	5	5000	5	5000
2013-11-18 00:00:00.000	5	5000	5	5000	5	5000
2013-11-19 00:00:00.000	5	5000	5	5000	5	5000

Then suspect answer data in table form:
_
_
SELECT [Date],[Branch1_Qty],[Branch1_Value],[Branch2_Qty],[Branch2_Value],[Branch3_Qty],[Branch3_Value], Branch1_Qty + Branch2_Qty + Branch3_Qty AS [Total_Qty], Branch1_Value + Branch2_Value + Branch3_Value AS [Total_Value] FROM  [cpqa].[tbl_OZ_notevenPivot]		 

Date	Branch1_Qty	Branch1_Value	Branch2_Qty	Branch2_Value	Branch3_Qty	Branch3_Value	Total_Qty	Total_Value
2013-11-15 00:00:00.000	5	5000	5	5000	5	5000	15	15000
2013-11-16 00:00:00.000	5	5000	5	5000	5	5000	15	15000
2013-11-17 00:00:00.000	5	5000	5	5000	5	5000	15	15000
2013-11-18 00:00:00.000	5	5000	5	5000	5	5000	15	15000
2013-11-19 00:00:00.000	5	5000	5	5000	5	5000	15	15000
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900