Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Stored Procedure

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-06-19 : 16:17:16
Eng writes "Is there a way to build a stored procedure where a passing parameter is a name of the column in a table, which needs to be used in the stored procedure query?

---- Here is a sample of what I want to do ----
CREATE PROCEDURE dbo.sp_Etest
@field_name varchar(40),
@field_value varchar(40)
AS

SELECT *
FROM [some_table]
WHERE @field_name = @field_value
------------------------------------------------
When I excute : execute sp_Etest 'jtypecode', 'RNF'
-------------------------------------------------

It doesn't work; since it compares my passing parameters as strings and my WHERE becomes...
'jtypecode' = 'RNF' [which is not what I want]

Is there a way to write a stored procedure so that my WHERE should say...
jtypecode = 'RNF'

I need to always pass the column name(s) with its value(s). That's how the ASP page will be set up. Any thoughts?????"
   

- Advertisement -