Subject Data in Row Format, Need To Display In Columun Format
Author Vishal Tiwari
Hi All,
 
 
I thing attachment is not working with this forum, any way...

I have a table named as "Book_Details", table structure is as follows:
 
sYear Varchar(4) Not Null,
sYearMonth Varchar(6) Not Null,
sBranchCode Varchar(15) Not Null,
sBook_Name Varchar(50) Not Null,
rBook_Price Numeric(15, 2) Not Null,
iCopy_Sold Integer Not Null,
rTot_Amount Numeric(15, 2) Not Null,
Primary key (sYear, sYearMonth, sBranchCode, sBook_Name)

 
Data in the database looks like: 






sYear          


sYearMonth

sBranchCode

sBook_Name 

rBook_Price

iCopy_Sold

Tot_Amount


2009

200912

Branch1

Book1

1500.00

50

75000.00


2009

200912

Branch2

Book1

1500.00

70

105000.00


2009

200912

Branch1

Book5

1000.00

50

50000.00


2010

201001

Branch1

Book1

2000.00

60

120000.00


2010

201001

Branch2

Book1

1200.00

50

60000.00


2010

201001

Branch1

Book5

1500.00

50

75000.00
 
 
 

 

 
 
 
 
 
 
 
Required SQL Result:
 





Branch

Code

Book1
Price In 200912

Book1
Price In 201001

Diff.
In Copy
Sold

Diff.
In Tot.
Amt.

Book5
Price In 200912

Book5
Price In 201001

Diff.
In Copy
Sold

Diff.
In Tot.
Amt.


Branch1

1500.00

2000.00

10

45000.00

1000.00

1500.00

0

25000.00


Branch2

1500.00

1200.00

20

45000.00

0.00

0.00

0

0.00

 
 
 
I am still trying, but since the data available in row the format, I am struggling with the required result.
 
Please let me know, how could I achieve this.
 
Thanks in Advance.
 
 
Vishal
 
 
 
 
 
 



[Non-text portions of this message have been removed]