BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Get variant column from a table

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (SQL Servers)
View previous topic :: View next topic  
Author Message
John Smith
Guest





PostPosted: Tue Apr 26, 2005 1:15 am    Post subject: Get variant column from a table Reply with 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
Maurice Telkamp
Guest





PostPosted: Tue Apr 26, 2005 9:30 am    Post subject: Re: Get variant column from a table Reply with quote



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
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (SQL Servers) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.