Reputation: 1269
My question: once I receive the parameter value, I want to modify the contents.
E.g. a string parameter value is: FullName,Address,Category
I want to change FullName
to l.FullName
and Category
to c.Category
and keep the rest same.
ALTER PROCEDURE [dbo].[TableA] @ColNames VARCHAR(1000)
AS
BEGIN
//I want to modify the contents of @ColNames here
Upvotes: 0
Views: 1883
Reputation: 134
ALTER PROCEDURE [dbo].[TableA] @ColNames VARCHAR(1000)
AS
BEGIN
SET
@ColNames = REPLACE(@ColNames, 'FullName', 'l.FullName')
;
SET
@ColNames = REPLACE(@ColNames, 'Category', 'c.Category')
;
Upvotes: 0
Reputation: 232
declare
@ColNames varchar(50)
select @ColNames = replace(@ColNames, 'FullName', 'l.FullName');
select @ColNames = replace(@ColNames, 'Category', 'c.Category');
Upvotes: 0
Reputation: 32713
Yes, you can do that - @ColNames is a variable - you can manipulate the contents of it.
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")
Upvotes: 0
Reputation: 1270443
How about this?
select @ColNames = replace(@ColNames, 'FullName', 'l.FullName');
select @ColNames = replace(@ColNames, 'Category', 'c.Category');
Upvotes: 1