-1
レポートビルダーで過去12ヶ月間のMTBFを月別にグラフ表示しようとしています。私は、私が望む方法を示すSQLクエリの結果を持っていた。レポートビルダーでグラフに使用される結果の書式設定
例:
December-16 January-17 February-17 March-17 Current
39.24 39.55 40.28 42.77 63.21
私はそれが一つのシリーズとしてデータを見て、一緒にすべてのデータを妨害されたグラフにデータセットを追加するには、レポートビルダでそれを入れてみてください。私はこれ以上のようにそれをフォーマットする必要があると思うが、確かではない。どんな提案も役に立ちます。
MTBF Month
63.21 Current
42.77 March-17
40.28 February-17
39.55 January-17
39.24 December-16
Here is my current Query:
Declare @CurrentDate as DateTime
Declare @CurrentMonth as DateTime
Declare @CurrentMonthEnd as DateTime
Declare @CurrentMonthString as VarChar(20)
Declare @CurrentMonthStringEnd as VarChar(20)
Declare @CurrentMonthName as Varchar(20)
Declare @PreviousMonth as DateTime
Declare @PreviousMonthEnd as DateTime
Declare @PreviousMonthString as VarChar(20)
Declare @PreviousMonthStringEnd as VarChar(20)
Declare @PreviousMonthName as Varchar(20)
Declare @PreviousMonth1 as DateTime
Declare @PreviousMonthEnd1 as DateTime
Declare @PreviousMonthString1 as VarChar(20)
Declare @PreviousMonthStringEnd1 as VarChar(20)
Declare @PreviousMonthName1 as Varchar(20)
Declare @PreviousMonth2 as DateTime
Declare @PreviousMonthEnd2 as DateTime
Declare @PreviousMonthString2 as VarChar(20)
Declare @PreviousMonthStringEnd2 as VarChar(20)
Declare @PreviousMonthName2 as Varchar(20)
Declare @PreviousMonth3 as DateTime
Declare @PreviousMonthEnd3 as DateTime
Declare @PreviousMonthString3 as VarChar(20)
Declare @PreviousMonthStringEnd3 as VarChar(20)
Declare @PreviousMonthName3 as Varchar(20)
Declare @PreviousMonth4 as DateTime
Declare @PreviousMonthEnd4 as DateTime
Declare @PreviousMonthString4 as VarChar(20)
Declare @PreviousMonthStringEnd4 as VarChar(20)
Declare @PreviousMonthName4 as Varchar(20)
Declare @PreviousMonth5 as DateTime
Declare @PreviousMonthEnd5 as DateTime
Declare @PreviousMonthString5 as VarChar(20)
Declare @PreviousMonthStringEnd5 as VarChar(20)
Declare @PreviousMonthName5 as Varchar(20)
Declare @PreviousMonth6 as DateTime
Declare @PreviousMonthEnd6 as DateTime
Declare @PreviousMonthString6 as VarChar(20)
Declare @PreviousMonthStringEnd6 as VarChar(20)
Declare @PreviousMonthName6 as Varchar(20)
Declare @PreviousMonth7 as DateTime
Declare @PreviousMonthEnd7 as DateTime
Declare @PreviousMonthString7 as VarChar(20)
Declare @PreviousMonthStringEnd7 as VarChar(20)
Declare @PreviousMonthName7 as Varchar(20)
Declare @PreviousMonth8 as DateTime
Declare @PreviousMonthEnd8 as DateTime
Declare @PreviousMonthString8 as VarChar(20)
Declare @PreviousMonthStringEnd8 as VarChar(20)
Declare @PreviousMonthName8 as Varchar(20)
Declare @PreviousMonth9 as DateTime
Declare @PreviousMonthEnd9 as DateTime
Declare @PreviousMonthString9 as VarChar(20)
Declare @PreviousMonthStringEnd9 as VarChar(20)
Declare @PreviousMonthName9 as Varchar(20)
Declare @PreviousMonth10 as DateTime
Declare @PreviousMonthEnd10 as DateTime
Declare @PreviousMonthString10 as VarChar(20)
Declare @PreviousMonthStringEnd10 as VarChar(20)
Declare @PreviousMonthName10 as Varchar(20)
Declare @PreviousMonth11 as DateTime
Declare @PreviousMonthEnd11 as DateTime
Declare @PreviousMonthString11 as VarChar(20)
Declare @PreviousMonthStringEnd11 as VarChar(20)
Declare @PreviousMonthName11 as Varchar(20)
Declare @PreviousMonth12 as DateTime
Declare @PreviousMonthEnd12 as DateTime
Declare @PreviousMonthString12 as VarChar(20)
Declare @PreviousMonthStringEnd12 as VarChar(20)
Declare @PreviousMonthName12 as Varchar(20)
Declare @SQLString as Varchar(Max)
Declare @SQLString1 as Varchar(Max)
Declare @SQLString2 as Varchar(Max)
Declare @SQLString3 as Varchar(Max)
Declare @Select12 as VarChar(MAX)
Declare @Select11 as VarChar(MAX)
Declare @Select10 as VarChar(MAX)
Declare @Select9 as VarChar(MAX)
Declare @Select8 as VarChar(MAX)
Declare @Select7 as VarChar(MAX)
Declare @Select6 as VarChar(MAX)
Declare @Select5 as VarChar(MAX)
Declare @Select4 as VarChar(MAX)
Declare @Select3 as VarChar(MAX)
Declare @Select2 as VarChar(MAX)
Declare @Select1 as VarChar(MAX)
Declare @Select as VarChar(MAX)
Declare @SelectCurrent as VarChar(MAX)
Declare @Formula as VarChar(100)
Declare @From as Varchar(200)
Declare @Where as Varchar(100)
IF (DatePart(mm,getdate()) > 1)
SET @PreviousMonth = DateFromParts(datepart(yyyy,getdate()),month(dateadd(Month,-1,getdate())),01)
Else
SET @PreviousMonth = DateFromParts(datepart(yyyy,getdate())-1,month(dateadd(Month,-1,getdate())),01)
IF (DatePart(mm,getdate()) > 2)
SET @PreviousMonth1 = DateFromParts(datepart(yyyy,getdate()),month(dateadd(Month,-2,getdate())),01)
Else
SET @PreviousMonth1 = DateFromParts(datepart(yyyy,getdate())-1,month(dateadd(Month,-2,getdate())),01)
IF (DatePart(mm,getdate()) > 3)
SET @PreviousMonth2 = DateFromParts(datepart(yyyy,getdate()),month(dateadd(Month,-3,getdate())),01)
Else
SET @PreviousMonth2 = DateFromParts(datepart(yyyy,getdate())-1,month(dateadd(Month,-3,getdate())),01)
IF (DatePart(mm,getdate()) > 4)
SET @PreviousMonth3 = DateFromParts(datepart(yyyy,getdate()),month(dateadd(Month,-4,getdate())),01)
Else
SET @PreviousMonth3 = DateFromParts(datepart(yyyy,getdate())-1,month(dateadd(Month,-4,getdate())),01)
IF (DatePart(mm,getdate()) > 5)
SET @PreviousMonth4 = DateFromParts(datepart(yyyy,getdate()),month(dateadd(Month,-5,getdate())),01)
Else
SET @PreviousMonth4 = DateFromParts(datepart(yyyy,getdate())-1,month(dateadd(Month,-5,getdate())),01)
IF (DatePart(mm,getdate()) > 6)
SET @PreviousMonth5 = DateFromParts(datepart(yyyy,getdate()),month(dateadd(Month,-6,getdate())),01)
Else
SET @PreviousMonth5 = DateFromParts(datepart(yyyy,getdate())-1,month(dateadd(Month,-6,getdate())),01)
IF (DatePart(mm,getdate()) > 7)
SET @PreviousMonth6 = DateFromParts(datepart(yyyy,getdate()),month(dateadd(Month,-7,getdate())),01)
Else
SET @PreviousMonth6 = DateFromParts(datepart(yyyy,getdate())-1,month(dateadd(Month,-7,getdate())),01)
IF (DatePart(mm,getdate()) > 8)
SET @PreviousMonth7 = DateFromParts(datepart(yyyy,getdate()),month(dateadd(Month,-8,getdate())),01)
Else
SET @PreviousMonth7 = DateFromParts(datepart(yyyy,getdate())-1,month(dateadd(Month,-8,getdate())),01)
IF (DatePart(mm,getdate()) > 9)
SET @PreviousMonth8 = DateFromParts(datepart(yyyy,getdate()),month(dateadd(Month,-9,getdate())),01)
Else
SET @PreviousMonth8 = DateFromParts(datepart(yyyy,getdate())-1,month(dateadd(Month,-9,getdate())),01)
IF (DatePart(mm,getdate()) > 10)
SET @PreviousMonth9 = DateFromParts(datepart(yyyy,getdate()),month(dateadd(Month,-10,getdate())),01)
Else
SET @PreviousMonth9 = DateFromParts(datepart(yyyy,getdate())-1,month(dateadd(Month,-10,getdate())),01)
IF (DatePart(mm,getdate()) > 11)
SET @PreviousMonth10 = DateFromParts(datepart(yyyy,getdate()),month(dateadd(Month,-11,getdate())),01)
Else
SET @PreviousMonth10 = DateFromParts(datepart(yyyy,getdate())-1,month(dateadd(Month,-11,getdate())),01)
IF (DatePart(mm,getdate()) > 12)
SET @PreviousMonth11 = DateFromParts(datepart(yyyy,getdate()),month(dateadd(Month,-12,getdate())),01)
Else
SET @PreviousMonth11 = DateFromParts(datepart(yyyy,getdate())-1,month(dateadd(Month,-12,getdate())),01)
IF (DatePart(mm,getdate()) > 13)
SET @PreviousMonth12 = DateFromParts(datepart(yyyy,getdate()),month(dateadd(Month,-13,getdate())),01)
Else
SET @PreviousMonth12 = DateFromParts(datepart(yyyy,getdate())-1,month(dateadd(Month,-13,getdate())),01)
SET @CurrentMonthName = '''Current'''
SET @PreviousMonthName = DateName(Month,@PreviousMonth) + '_' + Right(Cast(DatePart(yy,@PreviousMonth) as Varchar(20)),2)
SET @PreviousMonthName1 = DateName(Month,@PreviousMonth1) + '_' + Right(Cast(DatePart(yy,@PreviousMonth1) as Varchar(20)),2)
SET @PreviousMonthName2 = DateName(Month,@PreviousMonth2) + '_' + Right(Cast(DatePart(yy,@PreviousMonth2) as Varchar(20)),2)
SET @PreviousMonthName3 = DateName(Month,@PreviousMonth3) + '_' + Right(Cast(DatePart(yy,@PreviousMonth3) as Varchar(20)),2)
SET @PreviousMonthName4 = DateName(Month,@PreviousMonth4) + '_' + Right(Cast(DatePart(yy,@PreviousMonth4) as Varchar(20)),2)
SET @PreviousMonthName5 = DateName(Month,@PreviousMonth5) + '_' + Right(Cast(DatePart(yy,@PreviousMonth5) as Varchar(20)),2)
SET @PreviousMonthName6 = DateName(Month,@PreviousMonth6) + '_' + Right(Cast(DatePart(yy,@PreviousMonth6) as Varchar(20)),2)
SET @PreviousMonthName7 = DateName(Month,@PreviousMonth7) + '_' + Right(Cast(DatePart(yy,@PreviousMonth7) as Varchar(20)),2)
SET @PreviousMonthName8 = DateName(Month,@PreviousMonth8) + '_' + Right(Cast(DatePart(yy,@PreviousMonth8) as Varchar(20)),2)
SET @PreviousMonthName9 = DateName(Month,@PreviousMonth9) + '_' + Right(Cast(DatePart(yy,@PreviousMonth9) as Varchar(20)),2)
SET @PreviousMonthName10 = DateName(Month,@PreviousMonth10) + '_' + Right(Cast(DatePart(yy,@PreviousMonth10) as Varchar(20)),2)
SET @PreviousMonthName11 = DateName(Month,@PreviousMonth11) + '_' + Right(Cast(DatePart(yy,@PreviousMonth11) as Varchar(20)),2)
SET @PreviousMonthName12 = DateName(Month,@PreviousMonth12) + '_' + Right(Cast(DatePart(yy,@PreviousMonth12) as Varchar(20)),2)
SET @CurrentMonthString = Cast(getdate() as VarChar(20))
SET @PreviousMonthString = Cast(@PreviousMonth as VarChar(20))
SET @PreviousMonthString1 = Cast(@PreviousMonth1 as VarChar(20))
SET @PreviousMonthString2 = Cast(@PreviousMonth2 as VarChar(20))
SET @PreviousMonthString3 = Cast(@PreviousMonth3 as VarChar(20))
SET @PreviousMonthString4 = Cast(@PreviousMonth4 as VarChar(20))
SET @PreviousMonthString5 = Cast(@PreviousMonth5 as VarChar(20))
SET @PreviousMonthString6 = Cast(@PreviousMonth6 as VarChar(20))
SET @PreviousMonthString7 = Cast(@PreviousMonth7 as VarChar(20))
SET @PreviousMonthString8 = Cast(@PreviousMonth8 as VarChar(20))
SET @PreviousMonthString9 = Cast(@PreviousMonth9 as VarChar(20))
SET @PreviousMonthString10 = Cast(@PreviousMonth10 as VarChar(20))
SET @PreviousMonthString11 = Cast(@PreviousMonth11 as VarChar(20))
SET @PreviousMonthString12 = Cast(@PreviousMonth12 as VarChar(20))
Set @CurrentMonthStringEnd = Cast(Dateadd(Day,-365,getDate()) as VarChar(20))
Set @PreviousMonthStringEnd = Cast(Dateadd(Day,-365,@previousMonth) as VarChar(20))
Set @PreviousMonthStringEnd1 = Cast(Dateadd(Day,-365,@previousMonth1) as VarChar(20))
Set @PreviousMonthStringEnd2 = Cast(Dateadd(Day,-365,@previousMonth2) as VarChar(20))
Set @PreviousMonthStringEnd3 = Cast(Dateadd(Day,-365,@previousMonth3) as VarChar(20))
Set @PreviousMonthStringEnd4 = Cast(Dateadd(Day,-365,@previousMonth4) as VarChar(20))
Set @PreviousMonthStringEnd5 = Cast(Dateadd(Day,-365,@previousMonth5) as VarChar(20))
Set @PreviousMonthStringEnd6 = Cast(Dateadd(Day,-365,@previousMonth6) as VarChar(20))
Set @PreviousMonthStringEnd7 = Cast(Dateadd(Day,-365,@previousMonth7) as VarChar(20))
Set @PreviousMonthStringEnd8 = Cast(Dateadd(Day,-365,@previousMonth8) as VarChar(20))
Set @PreviousMonthStringEnd9 = Cast(Dateadd(Day,-365,@previousMonth9) as VarChar(20))
Set @PreviousMonthStringEnd10 = Cast(Dateadd(Day,-365,@previousMonth10) as VarChar(20))
Set @PreviousMonthStringEnd11 = Cast(Dateadd(Day,-365,@previousMonth11) as VarChar(20))
Set @PreviousMonthStringEnd12 = Cast(Dateadd(Day,-365,@previousMonth12) as VarChar(20))
Set @Formula = 'Cast(Round((COUNT (Distinct wojob.AssetID) *365.0)/(COUNT(*)),2) as Numeric(36,2))'
Set @From = ' FROM [Maint5k].[dbo].[woJob] INNER JOIN Maint5k.dbo.syJobType ON woJob.JobTypeID = syJobType.JobTypeID INNER JOIN Maint5k.dbo.pmAsset ON woJob.AssetID = pmAsset.AssetID'
Set @Where = ' and (pmAsset.Usertext2 = ''Critical'' or pmAsset.Usertext2 = ''Constraint'')'
SET @Select12 = ' (Select ' + @Formula + @From + ' Where syJobType.IsBreakDown = ''1'' and woJob.StartDate < ''' + @PreviousMonthString12 + ''' and woJob.StartDate > ''' + @PreviousMonthStringEnd12 + '''' + @Where + ')' + ' as ' + @PreviousMonthName12
SET @Select11 = ' (Select ' + @Formula + @From + ' Where syJobType.IsBreakDown = ''1'' and woJob.StartDate < ''' + @PreviousMonthString11 + ''' and woJob.StartDate > ''' + @PreviousMonthStringEnd11 + '''' + @Where + ')' + ' as ' + @PreviousMonthName11
SET @Select10 = ' (Select ' + @Formula + @From + ' Where syJobType.IsBreakDown = ''1'' and woJob.StartDate < ''' + @PreviousMonthString10 + ''' and woJob.StartDate > ''' + @PreviousMonthStringEnd10 + '''' + @Where + ')' + ' as ' + @PreviousMonthName10
SET @Select9 = ' (Select ' + @Formula + @From + ' Where syJobType.IsBreakDown = ''1'' and woJob.StartDate < ''' + @PreviousMonthString9 + ''' and woJob.StartDate > ''' + @PreviousMonthStringEnd9 + '''' + @Where + ')' + ' as ' + @PreviousMonthName9
SET @Select8 = ' (Select ' + @Formula + @From + ' Where syJobType.IsBreakDown = ''1'' and woJob.StartDate < ''' + @PreviousMonthString8 + ''' and woJob.StartDate > ''' + @PreviousMonthStringEnd8 + '''' + @Where + ')' + ' as ' + @PreviousMonthName8
SET @Select7 = ' (Select ' + @Formula + @From + ' Where syJobType.IsBreakDown = ''1'' and woJob.StartDate < ''' + @PreviousMonthString7 + ''' and woJob.StartDate > ''' + @PreviousMonthStringEnd7 + '''' + @Where + ')' + ' as ' + @PreviousMonthName7
SET @Select6 = ' (Select ' + @Formula + @From + ' Where syJobType.IsBreakDown = ''1'' and woJob.StartDate < ''' + @PreviousMonthString6 + ''' and woJob.StartDate > ''' + @PreviousMonthStringEnd6 + '''' + @Where + ')' + ' as ' + @PreviousMonthName6
SET @Select5 = ' (Select ' + @Formula + @From + ' Where syJobType.IsBreakDown = ''1'' and woJob.StartDate < ''' + @PreviousMonthString5 + ''' and woJob.StartDate > ''' + @PreviousMonthStringEnd5 + '''' + @Where + ')' + ' as ' + @PreviousMonthName5
SET @Select4 = ' (Select ' + @Formula + @From + ' Where syJobType.IsBreakDown = ''1'' and woJob.StartDate < ''' + @PreviousMonthString4 + ''' and woJob.StartDate > ''' + @PreviousMonthStringEnd4 + '''' + @Where + ')' + ' as ' + @PreviousMonthName4
SET @Select3 = ' (Select ' + @Formula + @From + ' Where syJobType.IsBreakDown = ''1'' and woJob.StartDate < ''' + @PreviousMonthString3 + ''' and woJob.StartDate > ''' + @PreviousMonthStringEnd3 + '''' + @Where + ')' + ' as ' + @PreviousMonthName3
SET @Select2 = ' (Select ' + @Formula + @From + ' Where syJobType.IsBreakDown = ''1'' and woJob.StartDate < ''' + @PreviousMonthString2 + ''' and woJob.StartDate > ''' + @PreviousMonthStringEnd2 + '''' + @Where + ')' + ' as ' + @PreviousMonthName2
SET @Select1 = ' (Select ' + @Formula + @From + ' Where syJobType.IsBreakDown = ''1'' and woJob.StartDate < ''' + @PreviousMonthString1 + ''' and woJob.StartDate > ''' + @PreviousMonthStringEnd1 + '''' + @Where + ')' + ' as ' + @PreviousMonthName1
SET @Select = ' (Select ' + @Formula + @From + ' Where syJobType.IsBreakDown = ''1'' and woJob.StartDate < ''' + @PreviousMonthString + ''' and woJob.StartDate > ''' + @PreviousMonthStringEnd + '''' + @Where + ')' + ' as ' + @PreviousMonthName
SET @SelectCurrent = ' (Select ' + @Formula + @From + ' Where syJobType.IsBreakDown = ''1'' and woJob.StartDate < ''' + @CurrentMonthString + ''' and woJob.StartDate > ''' + @CurrentMonthStringEnd + '''' + @Where + ')' + ' as ' + @CurrentMonthName
Set @SQLString = 'Select ' + @Select12 + ',' + @Select11 + ',' + @Select10 + ',' + @Select9 + ',' + @Select8 + ',' + @Select7 + ',' + @Select6 + ',' + @Select5 + ',' + @Select4 + ',' + @Select3 + ',' + @Select2 + ',' + @Select1 + ',' + @Select + ',' + @SelectCurrent
EXECUTE(@SQLString)
コードが正しく構成されていないと申し訳ありません。まだ学んでいる。おかげ