日期:2014-05-16 浏览次数:20402 次
select ','+ks+''+ cast(rs as varchar) from rs_table for xml path('')是什么意思?
','+ks+''+ cast(rs as varchar)又是什么意思?每个字的意思详解下','+ks''这+又是什么意思? 为什么要用+反正就是要详解!!求大神
----------------------------------------------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2014-03-03 07:48:42
-- Version:
-- Microsoft SQL Server 2012 (SP1) - 11.0.3128.0 (X64)
-- Dec 28 2012 20:23:12
-- Copyright (c) Microsoft Corporation
-- Enterprise Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: )
--
----------------------------------------------------------------
--> 测试数据:[rs_table]
if object_id('[rs_table]') is not null drop table [rs_table]
go
create table [rs_table]([ks] varchar(6),[rs] int)
insert [rs_table]
select '儿科',92 union all
select '内一科',225 union all
select '外一科',357 union all
select '外二科',391 union all
select '骨科',412
--------------开始查询--------------------------
select * from [rs_table]
go
select ','+ks+''+ cast(rs as varchar) from rs_table for xml path('')
go
select * from rs_table for xml path('')
go
select cast(rs as varchar) from rs_table for xml path('')
go
select ','+ks+'' from rs_table for xml path('')
----------------结果----------------------------
/*
ks rs
------ -----------
儿科 92
内一科 225
外一科 357
外二科 391
骨科 412
XML_F52E2B61-18A1-11d1-B105-00805F49916B
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
,儿科92,内一科225,外一科357,外二科391,骨科412
(5 row(s) affected)
XML_F52E2B61-18A1-11d1-B105-00805F49916B
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
<ks>儿科</ks><rs>92</rs><ks>内一科</ks><rs>225</rs><ks>外一科</ks><rs>357</rs><ks>外二科</ks><rs>391</rs><ks>骨科</ks><rs>412</rs>
(5 row(s) affected)
XML_F52E2B61-18A1-11d1-B105-00805F49916B
------------------------------