我的同事给了我一个复杂的 sql 查询。我想得到一列的MMYYYY
格式。我怎样才能实现它?以下是查询中的列部分(查询太长。所以我只粘贴列部分)。
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