如何将查询的记录都合并成为一个记录呢?其实实现的SQL语句写法并不复杂,接下来的SQL server内容就为您列出该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 行)