教您将记录合并的SQL语句写法
如何将查询的记录都合并成为一个记录呢?其实实现的SQL语句写法并不复杂,下面就为您列出该SQL语句,希望对您学习SQL语句有所启迪。
- create table t
- (tableid nchar(30))
- insert t
- select ’T1’ union all
- select ’T2’ union all
- select ’T3’ union all
- select ’T4’ union all
- select ’T5’ union all
- select ’T6’
- go
- create function f_he()
- returns @t table(col varchar(50))
- as
- begin
- declare @sql varchar(50)
- set @sql=’’
- select @sql=@sql+ltrim(rtrim(tableid)) from t
- insert @t values (@sql)
- return
- end
- go
- select * from t
- select * from dbo.f_he()
- drop function f_he
- drop table t
- col
- --------------------------------------------------
- T1T2T3T4T5T6
- (所影响的行数为 1 行)
【编辑推荐】
表添加字段的SQL语句写法
sql查询中time字段的使用
SQL Xml字段的修改方法
SQL定义Xml字段
SQL NULL值的相关知识
版权声明:
作者:后浪云
链接:https://www.idc.net/help/319771/
文章版权归作者所有,未经允许请勿转载。
THE END