类型转换,笛卡儿积和联合结果集

来源:互联网 发布:手机免费聊天软件 编辑:程序博客网 时间:2024/06/08 09:43
--类型转换--'当前时间' GETDATE()--第一种转换方式 将时间转换成nvarcharselect '当前时间'+CAST(GETDATE() as nvarchar(20)) --第二种方式select '当前时间'+ CONVERT(nvarchar(20),GETDATE())--优化第二种方式select '当前时间'+CONVERT(varchar(20),GETDATE(),111)select '当前时间'+CONVERT(varchar(20),GETDATE(),120)select '当前时间'+CONVERT(varchar(20),GETDATE(),104)select '当前时间'+CONVERT(varchar(20),GETDATE(),109)--如果是 null 显示后面的字符串select isnull(convert(varchar(20),Depss),'无')from Departmentselect cast(9.23 as int)--笛卡尔积select *from Stu ,Departmentselect*from Departmentselect*from stu--联合结果集--列数相同--类型相同--两个表可以合并--类型不相同是可以转换类型--union(去除重复,相当于默认应用了distinct)--效率低select DepID as 内容,DepName as 哈哈 ,depss as 哦 from Departmentunionselect*from stu--union all 不去除重复--效率高select DepID as 内容,DepName as 哈哈 ,depss as 哦 from Departmentunion allselect*from stu


 
阅读全文
0 0
原创粉丝点击