IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[mps_gen_proc_params_separate]') AND type = 'P')
DROP PROCEDURE [dbo].[mps_gen_proc_params_separate]
GO
CREATE PROCEDURE [dbo].[mps_gen_proc_params_separate]
@tablename varchar(100),
@excludefields varchar(max),
@sql_paramnames varchar(max) out,
@sql_paramtypes varchar(max) out
AS
BEGIN
SET NOCOUNT ON;

declare @s varchar(max)
declare @s1 varchar(max)
declare @index int
exec mps_gen_proc_params @tablename,@excludefields,@sql_paramnames out
set @s=replace(@sql_paramnames,CHAR(9),'')
set @s=replace(@s,CHAR(8),'')
while CHARINDEX('  ',@s) > 0
set @s=REPLACE(@s,'  ',' ');
set @s=REPLACE(@s,char(10),'');
set @s=REPLACE(@s,char(13),'');
set @s=REPLACE(@s,'@','')+',,';

set @sql_paramnames=''
set @sql_paramtypes=''

while @s > ''
begin
--处理空格 参数名称
set @index=CHARINDEX(' ',@s)
if @index >0
set @sql_paramnames+='{'+ SUBSTRING(@s,1,@index-1) +'},'
else
break
set @s = SUBSTRING(@s,@index+1,LEN(@s))
--处理逗号 (参数类型)
set @index=CHARINDEX(',',@s)
set @s1=SUBSTRING(@s,1,@index-1)
if CHARINDEX('numeric',@s1) >0 or CHARINDEX('NUMERIC',@s1) >0 or CHARINDEX('decimal',@s1) >0 or CHARINDEX('DECIMAL',@s1) >0
begin
set @index=CHARINDEX(',',@s,@index+1);
end
set @sql_paramtypes += SUBSTRING(@s,1,@index-1)+'|';
set @s = SUBSTRING(@s,@index+1,LEN(@s))
end
--去掉多余的分隔符
if LEN(@sql_paramnames) > 0
set @sql_paramnames = SUBSTRING(@sql_paramnames,1,LEN(@sql_paramnames)-1);
if LEN(@sql_paramtypes) > 0
set @sql_paramtypes = SUBSTRING(@sql_paramtypes,1,LEN(@sql_paramtypes)-1);
END