------------------程序做得再好,数据有问题照样是个死 !

类型转换函数:cast,convert

--类型转换函数
declare @score int=(select top 1 Studentresult from Result where StudentNo=1)
select '我的成绩是:'+@score --报错
--一共有两种转换函数
--cast(源数据 as 目标类型)
--convert(目标类型,源数据,格式)
go
declare @score int=(select top 1 Studentresult from Result where StudentNo=1)
select '我的成绩是:'+cast(@score as CHAR(3))
go
declare @score int=(select top 1 Studentresult from Result where StudentNo=1)
select '我的成绩是:'+CONVERT(char(3),@score)
--不同点。:convert有格式,可以对日期值设置格式
select GETDATE()
select CONVERT(varchar(30),GETDATE(),103)

posted @ 2015-03-19 22:13  俊落笔如歌  阅读(216)  评论(0编辑  收藏  举报
           人的本事不是与生俱来的,不是你掌握了多少,而是当你面对一个未知问题的时候,你能用多少时间来掌握!       ---------俊落笔如歌