TSQL替换我的存储过程字符串参数

时间:2014-08-28 11:04:52

标签: sql sql-server tsql stored-procedures

我的问题:一旦收到参数值,我想修改内容。

E.g。字符串参数值为:FullName,Address,Category

我想将FullName更改为l.FullName,将Category更改为c.Category,其余部分保持不变。

ALTER PROCEDURE [dbo].[TableA] @ColNames VARCHAR(1000)
AS
BEGIN
    //I want to modify the contents of @ColNames here

4 个答案:

答案 0 :(得分:1)

这个怎么样?

select @ColNames = replace(@ColNames, 'FullName', 'l.FullName');
select @ColNames = replace(@ColNames, 'Category', 'c.Category');

答案 1 :(得分:0)

是的,你可以这样做 - @ColNames是一个变量 - 你可以操纵它的内容。

ALTER PROCEDURE [dbo].[TableA] @ColNames VARCHAR(1000)
AS
BEGIN
    -- I want to modify the contents of @ColNames here
SET @ColNames = REPLACE(@ColNames, "FullName", "l.FullName")
SET @ColNames = REPLACE(@ColNames, "Category", "c.Category")

答案 2 :(得分:0)

ALTER PROCEDURE [dbo].[TableA] @ColNames VARCHAR(1000)
AS
BEGIN
    SET
        @ColNames = REPLACE(@ColNames, 'FullName', 'l.FullName')
        ;
    SET
        @ColNames = REPLACE(@ColNames, 'Category', 'c.Category')
        ;

答案 3 :(得分:0)

declare 
@ColNames varchar(50)


select @ColNames = replace(@ColNames, 'FullName', 'l.FullName');
select @ColNames = replace(@ColNames, 'Category', 'c.Category');