Quantcast
Viewing all articles
Browse latest Browse all 10045

Sorting Expression

Image may be NSFW.
Clik here to view.

 

The X-axis which is displayed is not sorted properly. 2007-2008 is a string. And when I convert Fields!CurrentMonth.value as CDATE(Fields!CurrentMonth.value ), I am getting error as cannot convert

String to date. Here it is sorting in Ascending order rather than Monthwise.

THE QUERY WHICH HAS BEEN WRITTEN:

createtable  #temp1(AIFR int,[Hours]int,[AIFR AVE] int, [HRS AVE] int, CurrentMonthvarchar(25))

Declare @aint

Declare @bint

Declare @cint

set @a=(Selectdistinctyear(convert(datetime,CurrentMonth))from  dbo.mst_tbl_SafetyStatisticsRpt

where convert(datetime,CurrentMonth)='2007-07-01')

set @b=(Selectdistinctyear(convert(datetime,CurrentMonth))from    dbo.mst_tbl_SafetyStatisticsRpt

where convert(datetime,CurrentMonth)=(cast(@Yearasvarchar)+'-'+'06'+'-'+'01'))

while (@a<= @b)

begin

set @c= @a + 1

insert into #temp1

Select nullas AIFR, nullas [Hours],

SUM(casewhen (convert(datetime,CurrentMonth))between(cast(@aasvarchar)+'-'+'07'+'-'+'01')and(cast(@casvarchar)+'-'+'06'+'-'+'01')then  (ATIAVEEMP)else 0 end )as [AIFR AVE],

SUM(casewhen (convert(datetime,CurrentMonth))between(cast(@aasvarchar)+'-'+'07'+'-'+'01')and(cast(@casvarchar)+'-'+'06'+'-'+'01')then  (HRSAVEEMP)else 0 end )as [HRS AVE],

casewhen @c <>(@b+1)then Cast(@aasVarchar)+''+'-'+''+CAST(@c asvarchar)endas CurrentMonth

                                                     2007-2008

from       dbo.mst_tbl_SafetyStatisticsRpt 

where      (convert(datetime,CurrentMonth))between(cast(@aasvarchar)+'-'+'07'+'-'+'01')and(cast(@casvarchar)+'-'+'06'+'-'+'01')

and              Plantid in(SELECT Plantid from dbo.mst_tbl_Plant innerjoin dbo.mst_tbl_MainLocationon

                                                           dbo.mst_tbl_Plant.LocationID= dbo.mst_tbl_MainLocation.LocationID

                                                                             where dbo.mst_tbl_MainLocation.LocationID= @LocationId)

and              @c <>(@b+1)

set              @a = @a + 1

end

select*from #temp1

UNIONALL

Select SUM(Nosworkinjuriesemp)as AIFR, SUM(NosHworknormaledemp)as [Hours],

      SUM(ATIAVEEMP)as [AIFR AVE],Sum(HRSAVEEMP)AS [HRS AVE],CurrentMonth

from dbo.mst_tbl_SafetyStatisticsRpt

innerjoin  dbo.tbl_Monthson

(SUBSTRING(DBO.MST_TBL_SAFETYSTATISTICSRPT.CURRENTMONTH, 1, 3)) = MonthDesc

innerjoin dbo.mst_tbl_Yearson (SUBSTRING(DBO.MST_TBL_SAFETYSTATISTICSRPT.CURRENTMONTH, 4, 4)) = YearDesc

wherePlantid in(SELECT Plantid from dbo.mst_tbl_Plant innerjoin dbo.mst_tbl_MainLocationon dbo.mst_tbl_Plant.LocationID= dbo.mst_tbl_MainLocation.LocationID

where dbo.mst_tbl_MainLocation.LocationID= @LocationId)

and  YearDesc = @Year

and  MonId between 1 and @Month

Groupby CurrentMonth

unionall

select SUM(Nosworkinjuriesemp)as AIFR, SUM(NosHworknormaledemp)as [Hours],

      SUM(ATIAVEEMP)as [AIFR AVE],Sum(HRSAVEEMP)AS [HRS AVE],

      CurrentMonth

from dbo.mst_tbl_SafetyStatisticsRpt

innerjoin dbo.tbl_Monthson (SUBSTRING(DBO.MST_TBL_SAFETYSTATISTICSRPT.CURRENTMONTH, 1, 3)) = MonthDesc

innerjoin  dbo.mst_tbl_Yearson (SUBSTRING(DBO.MST_TBL_SAFETYSTATISTICSRPT.CURRENTMONTH, 4, 4)) = YearDesc

wherePlantid in(SELECT Plantid from dbo.mst_tbl_Plant innerjoin dbo.mst_tbl_MainLocationon dbo.mst_tbl_Plant.LocationID= dbo.mst_tbl_MainLocation.LocationID

where dbo.mst_tbl_MainLocation.LocationID= @LocationId)

and  YearDesc = @Year - 1

and  MonId between @Month + 1 and 12

Groupby CurrentMonth

droptable #temp1


Thanks in advance, Akhila Vasishta




Viewing all articles
Browse latest Browse all 10045

Trending Articles