- 轉(zhuǎn)換數(shù)據(jù)類型:使用CAST函數(shù)來將一個(gè)數(shù)據(jù)類型轉(zhuǎn)換為另一個(gè)數(shù)據(jù)類型。例如,將一個(gè)字符串轉(zhuǎn)換為整數(shù)或?qū)⒁粋€(gè)日期轉(zhuǎn)換為字符串。
SELECT CAST('123' AS INT) AS integer_value
- 格式化日期:使用CAST函數(shù)將日期數(shù)據(jù)類型轉(zhuǎn)換為特定的日期格式。
SELECT CAST(GETDATE() AS DATE) AS formatted_date
- 轉(zhuǎn)換布爾值:使用CAST函數(shù)將布爾值轉(zhuǎn)換為整數(shù)或字符串。
SELECT CAST(1 AS VARCHAR(5)) AS boolean_value
- 轉(zhuǎn)換小數(shù):使用CAST函數(shù)將小數(shù)轉(zhuǎn)換為整數(shù)或其他數(shù)據(jù)類型。
SELECT CAST(3.14 AS INT) AS integer_value