sql - Same Data, two different results -
i have sql call gets data year , displays in month month breakdown per code below.
select materialcode, [1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12] (select mb.materialcode, datepart(m, date) [dp], weight issues iss join materialbatches mb on iss.materialbatchid = mb.id left join materials m on mb.materialcode = m.code issuetype = 'materialissue' , datepart(yyyy,date) = 2013 , weight > 0 , (coalesce(m.isnondispensematerial,0) = 0 or cast((select value configurationsettings name = 'includenondispenseweights') varchar(10)) = 'true')) pivot (sum(weight) i.dp in ( [1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12] )) pvt
this code needs change make starting selected month changeable. using code below 948 more records \ row back.
select code, [1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12] (select mb.code, datepart(m, date) [dp], weight issues iss join batches mb on iss.id = mb.id left join mats m on mb.code = m.code issuetype = 'matissue' , year(date) = 2013 , month(date) = 01 or year(date) = 2013 , month(date) = 02 or year(date) = 2013 , month(date) = 03 or year(date) = 2013 , month(date) = 04 or year(date) = 2013 , month(date) = 05 or year(date) = 2013 , month(date) = 06 or year(date) = 2013 , month(date) = 07 or year(date) = 2013 , month(date) = 08 or year(date) = 2013 , month(date) = 09 or year(date) = 2013 , month(date) = 10 or year(date) = 2013 , month(date) = 11 or year(date) = 2013 , month(date) = 12 , weight > 0 , (coalesce(m.isnondisp,0) = 0 or cast((select value configurationsettings name = 'includenondisp') varchar(10)) = 'true')) pivot(sum(weight) i.dp in ( [1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12] )) pvt
can please let me know, going wrong?
have @ parantheses, try this:
select code, [1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12] (select mb.code, datepart(m, date) [dp], weight issues iss join batches mb on iss.id = mb.id left join mats m on mb.code = m.code issuetype = 'matissue' , year(date) = 2013 , weight > 0 , (coalesce(m.isnondisp,0) = 0 or cast((select value configurationsettings name = 'includenondisp') varchar(10)) = 'true')) pivot(sum(weight) i.dp in ( [1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12] )) pvt
Comments
Post a Comment