create table t
(tableid nchar(30))
(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
本文介绍了一个使用T-SQL创建表并定义存储过程的例子。通过创建一个包含若干记录的简单表,接着定义了一个函数来处理这些数据。该函数将表中的所有记录转换为字符串形式并返回。这个例子展示了如何在SQL中动态构建查询。
4385

被折叠的 条评论
为什么被折叠?



