 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
John Smith Guest
|
Posted: Tue Apr 26, 2005 1:15 am Post subject: Get variant column from a table |
|
|
I have a stored procedure which have two parameters: @columnname and
@id,I want to get specified column's record value by @columnname
parameter and id equals to the @id parameter.but I don't know how to
write that sp.it should looks like:
CREATE PROCEDURE dbo.StoreProcedure
@ColumnName varchar(255),
@ID varchar(255),
@Value varchar(255) OUTPUT
AS
SELECT @Value = @ColumnName FROM MyTable WHERE ID = @ID
RETURN
but the code is not correct.how to do that?thanks
|
|
| Back to top |
|
 |
Maurice Telkamp Guest
|
Posted: Tue Apr 26, 2005 9:30 am Post subject: Re: Get variant column from a table |
|
|
You will have to build a SQL-string in your stored procedure, and execute it
using sp_executeSQL
for example
DECLARE @sql varchar(1000)
SET @sql='SELECT ' + @ColumnName + ' FROM myTable WHERE .....etc
EXEC sp_ExecuteSQL @sql
"John Smith" <thecoder (AT) 163 (DOT) com> wrote
| Quote: | I have a stored procedure which have two parameters: @columnname and
@id,I want to get specified column's record value by @columnname
parameter and id equals to the @id parameter.but I don't know how to
write that sp.it should looks like:
CREATE PROCEDURE dbo.StoreProcedure
@ColumnName varchar(255),
@ID varchar(255),
@Value varchar(255) OUTPUT
AS
SELECT @Value = @ColumnName FROM MyTable WHERE ID = @ID
RETURN
but the code is not correct.how to do that?thanks
|
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|