使用 CAST:
CAST ( expression AS data_type )
使用 CONVERT:
CONVERT (data_type[(length)], expression [, style])
將 字符串轉換爲int cast ('2' as int)
將 int轉換爲varchar convert(varchar(20), 2)
需注意的是不要把cast寫成case cast和case在查詢分析器中是相同的顏色。。我就犯了這樣的錯誤。暈死。
select year(getDate()),month(getDate()),day(getDate()) 年份月份日子
convert(varchar(10),getdate(),120) 取到 yyyy-mm-dd格式的數據