IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[sys_Sql_genReplace]') AND type = 'P')
DROP PROCEDURE [dbo].[sys_Sql_genReplace]
GO
--sys_Sql_genReplace @parseid,@repname,@script2 output

create procedure [dbo].[sys_Sql_genReplace](
@parseid int,
@repname varchar(20),
@script varchar(2000) output
)as
begin
declare @repExp varchar(200)
,@curInd int,@varType varchar(20),@varName varchar(20),@fromInd int,@toInd int,@tmpS varchar(2000)
,@s varchar(500),@tbname varchar(20),@script2 varchar(2000),@tbfld varchar(50)
set @script = ''
select @repExp=repExp from sys_sql_replace where parseid=@parseid  and repname=@repname
if (@repExp is null or len(@repExp)<2)
return

select @curInd=1,@fromInd=1
exec sys_sql_getNextSysVar @repExp,@curInd,@varType output,@varName output,@fromInd output ,@toInd output
--结束判断
if (@varType is null or @varName is null) -- 为空，忽略该变量
return
if (@varType = 'global')
select @script='@' + @repname + '__'
else if (@varType='field')
begin
select top 1 @tbname=tbname,@tbfld=tbfld from flatFld
where parseID=@parseid and fldname=@varName

select @script='@' + @tbname + '_'+@tbfld + '__'
end

if (@script is null)
set @script = ''
 
end