|
-
January 20th, 2006, 05:13 AM
#1
HowTo: Pass a columnname as parametername in stored procedure
Normally you pass values as parameters.
But how can I pass a columnname as parameter in a stored procedure.
The procedure should look like somehow.
select * from A where @columname = 'Test'
Regards,
Maurice
-
January 20th, 2006, 05:39 AM
#2
Re: HowTo: Pass a columnname as parametername in stored procedure
Dear Maurice,
You can pass column name as value of Parameter in Stored Procedure but the functionality you want to implement is not possible. You can achieve the functionality by changing your following line with my code:
Your Line of Code
select * from A where @columname = 'Test'
My Line of Code
DECLARE @sqlString VARCHAR(8000)
SET @sqlString = 'select * from A where ' + @columname + ' = ''test'''
execute(@sqlString)
Hope this will solve u r problem.
Enjoy,
Gurdarshan Singh
L.S.E. (Project Lead)
InterGlobe Technologies Pvt. Ltd.
Mobile #: 9891397798 (India)
[email protected]
[email protected]
Always Think Positive whatever may be the Situation.
Please rate my suggestion/response if you find it suitable or fulfill your requirement.
-
January 20th, 2006, 05:46 AM
#3
Re: HowTo: Pass a columnname as parametername in stored procedure
How can the parameter @columnname be descibed in the stored procedure?
Maybe a small example would help.
Is it like??
CREATE PROCEDURE Test
(
DECLARE @sqlString VARCHAR(8000)
@COLUMNNAME varchar(30)
)
AS
SET @sqlString = 'select * from A where ' + @columname + ' = ''test'''
-
January 20th, 2006, 05:49 AM
#4
Re: HowTo: Pass a columnname as parametername in stored procedure
Dear Maurice,
No, example like below:
CREATE PROCEDURE Test
(
@COLUMNNAME varchar(30)
)
AS
BEGIN
DECLARE @sqlString VARCHAR(8000)
SET @sqlString = 'select * from A where ' + @columname + ' = ''test''' execute(@sqlString)
END
Enjoy,
Gurdarshan Singh
L.S.E. (Project Lead)
InterGlobe Technologies Pvt. Ltd.
Mobile #: 9891397798 (India)
[email protected]
[email protected]
Always Think Positive whatever may be the Situation.
Please rate my suggestion/response if you find it suitable or fulfill your requirement.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|