同僚から提供された複雑な SQL クエリがあります。MMYYYY
フォーマットで1列を取得したい。どうすれば達成できますか?以下は、クエリの列部分です(クエリが長すぎるため、列部分のみを貼り付けています)。
CASE
WHEN len(datepart (WEEK, cast(cast(month(from_date) AS VARCHAR(2)) + '/' + cast(xx.day_val AS VARCHAR(2)) + '/' + cast(year(from_date) AS VARCHAR(4)) AS DATETIME))) = 1
THEN '0' + datepart (WEEK, cast(cast(month(from_date) AS VARCHAR(2)) + '/' + cast(xx.day_val AS VARCHAR(2)) + '/' + cast(year(from_date) AS VARCHAR(4)) AS DATETIME))
ELSE datepart (WEEK, cast(cast(month(from_date) AS VARCHAR(2)) + '/' + cast(xx.day_val AS VARCHAR(2)) + '/' + cast(year(from_date) AS VARCHAR(4)) AS DATETIME))
END AS week_number