Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Firstly didn't saw SQL 2000, because i was busy in solving the Question.</p> <pre><code>create table consumption ( code varchar(6), prodname varchar(50), department varchar(20), netqty decimal(10,2), netmrp decimal(10,2) ) ; insert into consumption values ('U00180','USG JELLY IM-K','SONO',11.4,130.40) insert into consumption values ('U00280','UNIDINE 1 LITRE SOLUTION','AKD',1.4,10.40) insert into consumption values ('V02401','VOLINI GEL 50GM','PHYSIOTHERAPY',8,15) insert into consumption values ('V02402','X RAY FILM DIGITAL 14"X 17"','MRI',3,26.40) insert into consumption values ('U00380','TROPAC P DROPS ','AKD',21.46,56.78) insert into consumption values ('U00380','TROPAC P DROPS ','AKD',10,10) ; DECLARE @cols1 AS NVARCHAR(MAX), @query1 AS NVARCHAR(MAX), @query2 AS NVARCHAR(MAX); SET @cols1 = STUFF((SELECT distinct ',' + QUOTENAME(c.department) FROM consumption c FOR XML PATH(''), TYPE ).value('.', 'NVARCHAR(MAX)') ,1,1,'') set @query1 = 'select t.code,t.prodname, t.AKD as netqtyAKD,t1.AKD as netmrpAKD, t.MRI as netqtyMRI,t1.MRI as netmrpMRI, t.PHYSIOTHERAPY as netqtyPHYSIOTHERAPY,t1.PHYSIOTHERAPY as netmrpPHYSIOTHERAPY, t.SONO as netqtySONO,t1.SONO as netmrpSONO from ( SELECT code,prodname, ' + @cols1 + ' from ( select code , prodname , department , sum(netqty) as netqty from consumption group by code , department , prodname ) x pivot ( sum(netqty) for department in (' + @cols1 + ') ) p )t inner join (SELECT code,prodname, ' + @cols1 + ' from ( select code , prodname , department , sum(netmrp) as netmrp from consumption group by code , department , prodname ) x pivot ( sum(netmrp) for department in (' + @cols1 + ') ) p )t1 on t.code=t1.code and t.prodname=t1.prodname' </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload