/////////////// Sql problem
SELECT 'Data'as [Totals], sum(isnull([Avare],0))[Avare],sum(isnull([Blackgram],0))[Blackgram],sum(isnull([Cowpea],0))[Cowpea],sum(isnull([Greengram],0))[Greengram],sum(isnull([Horsegram],0))[Horsegram],sum(isnull([Madaki],0))[Madaki],sum(isnull([TotalPulses],0))[TotalPulses],sum(isnull([Tur],0))[Tur] FROM [tbl_AgriCrop_AreaSown]
///////// Solution
SELECT
field[Crops],value[Data (Ha.)]FROM(
SELECT sum(isnull([Avare],0))[Avare],sum(isnull([Blackgram],0))[Blackgram],sum(isnull([Cowpea],0))[Cowpea],sum(isnull([Greengram],0))[Greengram],sum(isnull([Horsegram],0))[Horsegram],sum(isnull([Madaki],0))[Madaki],sum(isnull([TotalPulses],0))[TotalPulses],sum(isnull([Tur],0))[Tur] FROM
[tbl_AgriCrop_AreaSown]
)Dt
unpivot
(
value
for field in ([Avare],[Blackgram],[Cowpea],[Greengram],[Horsegram],[Madaki],[TotalPulses],[Tur])
)un
////// result
No comments:
Post a Comment