システムにポリシーがあります
PolRef Start End
POL123 22/11/2012 23/12/2014
POL212 24/09/2012 23/10/2012
POL214 23/08/2012 29/09/2012
ユーザーにレポートの日付を尋ねています。ユーザーは2012年10月24日を入力します。@StartDate
これから、月ごとの四半期を導き出します。
set @currentMonth = Month(@StartDate)
if @currentMonth = 1 or @currentMonth = 2 or @currentMonth = 3 begin set @startmonth = 1 set @endmonth = 3 end
if @currentMonth = 4 or @currentMonth = 5 or @currentMonth = 6 begin set @startmonth = 4 set @endmonth = 6 end
if @currentMonth = 7 or @currentMonth = 8 or @currentMonth = 9 begin set @startmonth = 7 set @endmonth = 9 end
if @currentMonth = 10 or @currentMonth = 11 or @currentMonth = 12 begin set @startmonth = 10 set @endmonth = 12 end
次に、日付範囲を取得します。
@quarterStartDate = CAST(CAST(YEAR(@StartDate) AS varchar) + '-' + CAST(@startMonth AS varchar) + '-' + '01') AS Date)
@quarterEndDate = CAST(CAST(YEAR(@EcdDate) AS varchar) + '-' + CAST(@endMonth AS varchar) + '-' + '31') AS Date)
これにより、2012年1月10日と2012年12月31日になります。基本的に、この四半期にあるポリシーのみを戻すためのスクリプトが必要です。ポリシーは、四半期の日付範囲全体にまたがる必要はなく、四半期の日付範囲に存在するだけです。
期待される結果は
PolRef Start End
POL123 22/11/2012 23/12/2014
POL212 24/09/2012 23/10/2012
Pol123は、四半期の日付範囲にまたがっているために表示されます。Pol212は、その四半期の日付範囲で期限切れになるため、そこにあります。Pol214は、この四半期にまたがったり、期限切れになったり、開始したりしないため、表示されません。
どんな助けでも大歓迎です