0
我有以下SQL查詢(SQL Server 2008中):如何獲得在SQL查詢一週格式化字符串
SELECT sum(data.freq) as freq,data.week as week FROM (
SELECT
count(daterequested) as freq,
datepart(wk,daterequested) as week,
daterequested
FROM request ma
JOIN contracts mc ON (mc.uid= ma.uid)
JOIN groups og ON og.groupuid = mc.groupuid
JOIN member m ON (m.memberuid = mc.memberuid)
WHERE daterequested BETWEEN
DATEADD(MONTH,-1,GETDATE())
AND
GETDATE()
AND isdeleted = 0
GROUP BY datepart(wk,daterequested),daterequested
--ORDER BY daterequested ASC
) data
GROUP BY data.week
結果是與下列數據的表:
而不是顯示周編號我想顯示格式如下星期:
MM/dd
其中MM =月,dd是一週開始的日期。
如果我可以從一週的第一天開始,然後是中間斜線,然後是該周的最後一天,最後是月份,那將會很好:例如:11-17/04(4月11日至17日)等
這裏是最後的表,我想獲得:
任何線索?
要小心,因爲datapart(WK,ADATE)返回年份的周,當你有多個年的數據你的小組由可能不會返回預期的結果。 – Tim3880