Hi Everyone I have wrote a query as SELECT PD.Name,PD.ContactNumber,Sum(cast(dbo.GetNumericValue(GI.AAY_Wheat)as numeric(18,0)))[Allocation], 'Week '+cast(DATEPART(wk, GI.EnteredOn)as varchar(50)) AS WeekNumber, sum(cast(dbo.GetNumericValue(GI.AAY_Wheat)as numeric(18,0))) AS [Consumtion]FROM PDS_GodownCallInfo GIfull join PDS_GodownAllocation GA on GA.ContactNumber=GI.ContactNumberfull join PDS_ShopOwnnerContactDetails PD on PD.ContactNumber=GI.ContactNumberWHERE GI.EnteredOn >= '2013-01-01' AND GI.EnteredOn < '2013-11-30'GROUP BY DATEPART(wk, GI.EnteredOn),PD.Name,PD.ContactNumberand its output is as Name ContactNumber Allocation WeekNumber ConsumtionNULL NULL 1485 Week 44 1485Amit Singh 8091366307 220 Week 44 220Anil Semwal 9418497722 1500 Week 44 1500Rakesh Thakur 8091022334 220 Week 44 220Rakesh Verma 8627811198 220 Week 44 220NULL NULL 1445 Week 45 1445Amit Singh 8091366307 1446 Week 45 1446Rakesh Thakur 8091022334 0 Week 45 0Samridh Dhawan 9805396622 45 Week 45 45then I write a pivot query as below:SELECT *FROM ( SELECT PD.Name,PD.ContactNumber,Sum(cast(dbo.GetNumericValue(GI.AAY_Wheat)as numeric(18,0)))[Allocation], 'Week '+cast(DATEPART(wk, GI.EnteredOn)as varchar(50)) AS WeekNumber, sum(cast(dbo.GetNumericValue(GI.AAY_Wheat)as numeric(18,0))) AS [Consumtion]FROM PDS_GodownCallInfo GIfull join PDS_GodownAllocation GA on GA.ContactNumber=GI.ContactNumberfull join PDS_ShopOwnnerContactDetails PD on PD.ContactNumber=GI.ContactNumberWHERE GI.EnteredOn >= '2013-01-01' AND GI.EnteredOn < '2013-11-30'GROUP BY DATEPART(wk, GI.EnteredOn),PD.Name,PD.ContactNumber) as dataPIVOT( sum(Consumtion) FOR [WeekNumber] IN (week44,week45))AS pand Its output is as bellowName ContactNumber Allocation week44 week45NULL NULL 1445 NULL NULLNULL NULL 1485 NULL NULLAmit Singh 8091366307 220 NULL NULLAmit Singh 8091366307 1446 NULL NULLAnil Semwal 9418497722 1500 NULL NULLRakesh Thakur 8091022334 0 NULL NULLRakesh Thakur 8091022334 220 NULL NULLRakesh Verma 8627811198 220 NULL NULLSamridh Dhawan 9805396622 45 NULL NULLthere is values for Consumtion is showing NULL.can any one help me how can I fix the issue?
↧