How to show ed,cess in my query? [Resolved]

Posted by Raghuldrag under Sql Server on 11/5/2014 | Points: 10 | Views : 577 | Status : [Member] | Replies : 3
Hi Friends,


I ve the two tables like






Detail:
-------

create table detail
(
grn_no varchar(55),
po_no varchar(50),
vendor_no numeric(10,2),
Formul_id varchar(50),
Adjust_code varchar(50),
adjus_value float
)



insert into detail values ('Grn/0001/14-15','po/00011/14-15/','5000','ED12','ED12','500')
values ('Grn/0001/14-15','po/00011/14-15/','5000','CST','CST12','50')
values ('Grn/0001/14-15','po/00011/14-15/','5000','CES6','CES6','5')
values ('Grn/0001/14-15','po/00011/14-15/','5000','VAT','VAT','0')
values ('Grn/0001/14-15','po/00011/14-15/','5000','HCES2','HCES2','2.50')



here my expecting o/p:
-----------

i wanna display ED ,CESS ,HCESS,VAT in seperate columns in output How to that?




Responses

Posted by: Bandi on: 11/6/2014 [Member] [MVP] Platinum | Points: 50

Up
0
Down

Resolved
Did you get the solution from above reply ?

if YES, mark it as answer; else post me back where it is not suited for ur output

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Raghuldrag, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: vishalneeraj-24503 on: 11/6/2014 [Member] [MVP] Platinum | Points: 25

Up
0
Down
For this,you have to write a Case statemen t and in the case statement just give Formul_id = VAT in where condition and name the whole Case statement to VAT.And also do it for ED ,CESS ,HCESS.So you have total 4 case statement in a query.

And for Case statement refer:-
http://www.dotnet-tricks.com/Tutorial/sqlserver/1MS1120313-Understanding-Case-Expression-in-SQL-Server-with-Example.html
http://blog.sqlauthority.com/2007/04/14/sql-server-case-statementexpression-examples-and-explanation/
http://www.codeproject.com/Articles/39103/A-Simple-Use-of-SQL-CASE-Expression
http://www.1keydata.com/sql/sql-case.html

Raghuldrag, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 11/6/2014 [Member] [MVP] Platinum | Points: 25

Up
0
Down
SELECT *

FROM (SELECT grn_no, po_no, vendor_no, Adjust_code, adjus_value FROM detail ) p
PIVOT ( SUM(adjus_value) FOR Adjust_Code IN ([ED12], [CST12], [CES6], [VAT], [HCES2])) pvt


Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Raghuldrag, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response