2011-05-10 31 views
0

我有一個查詢將返回一組日期。我想把這些值放在'[]'中。將sql結果括在[

我的查詢是

SELECT distinct convert(varchar, track_empHours_date, 103) 
      as track_empHours_date 
    FROM tbl_track_empHours 
    WHERE tbl_track_empHours.track_empHours_main_usr_id_fk = '268' 
     AND track_empHours_date BETWEEN '5/09/2011' AND '5/15/2011' 

任何幫助表示讚賞

+3

您收到了什麼錯誤? – 2011-05-10 09:49:55

+0

您能否確認track_empHours_date包含您的日期範圍的值? – 2011-05-10 09:51:28

+0

...爲什麼從原始文章中刪除方括號? – 2011-05-10 10:10:31

回答

0
SELECT distinct '[' + convert(varchar, track_empHours_date, 103) + ']' 
     as track_empHours_date 
FROM tbl_track_empHours 
WHERE tbl_track_empHours.track_empHours_main_usr_id_fk = '268' 
    AND track_empHours_date BETWEEN '5/09/2011' AND '5/15/2011' 
2

您還可以使用QUOTENAME這一點。

SELECT 
    DISTINCT QUOTENAME(CONVERT(VARCHAR, track_empHours_date, 103)) 
                 AS track_empHours_date ... 
+0

很高興我讀到這個 ​​- 我不知道'QUOTENAME'函數。 – Yuck 2011-05-10 13:01:01