if object_id('tabA') is not null
drop table tabA
if object_id('tabB') is not null
drop table tabB
if object_id('fnStringJoin') is not null
drop function fnStringJoin
GO
----创建字符串连接函数
create function fnStringJoin(@xh int)
returns varchar(1000)
as
begin
declare @str varchar(1000)
set @str = ''
select @str = @str + zfc02 from tabB where xh = @xh
return @str
end
GO
----创建测试数据
create table tabA(xh int,zfc01 varchar(20))
create table tabB(xh int,zfc02 varchar(20))
insert tabA
select 123,'字段内容'
insert tabB
select 123,'我们' union all
select 123,'你们' union all
select 123,'他们' union all
select 123,'它们' union all
select 123,'她们' union all
select 123,'人们'----查询
select xh,zfc01 + dbo.fnStringJoin(xh) as zfc from tabA----清除测试环境
drop table tabA,tabB
drop function fnStringJoin/*结果
xh zfc
----------------------------------------------
123 字段内容我们你们他们它们她们人们
*/
drop table tabA
if object_id('tabB') is not null
drop table tabB
if object_id('fnStringJoin') is not null
drop function fnStringJoin
GO
----创建字符串连接函数
create function fnStringJoin(@xh int)
returns varchar(1000)
as
begin
declare @str varchar(1000)
set @str = ''
select @str = @str + zfc02 from tabB where xh = @xh
return @str
end
GO
----创建测试数据
create table tabA(xh int,zfc01 varchar(20))
create table tabB(xh int,zfc02 varchar(20))
insert tabA
select 123,'字段内容'
insert tabB
select 123,'我们' union all
select 123,'你们' union all
select 123,'他们' union all
select 123,'它们' union all
select 123,'她们' union all
select 123,'人们'----查询
select xh,zfc01 + dbo.fnStringJoin(xh) as zfc from tabA----清除测试环境
drop table tabA,tabB
drop function fnStringJoin/*结果
xh zfc
----------------------------------------------
123 字段内容我们你们他们它们她们人们
*/
return varchar(1000)
as
declare t varchar(1000)
set t = ''
select t = t + zfc02
from (select xh,zfc01 from a union all select xh,zfc02 from b)A
where xh = p_xhselect getCol(xh) from a