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)
 Column Name as parameter

Author  Topic 

dnagahawatte
Starting Member

24 Posts

Posted - 2004-06-22 : 11:17:27
Hi Guys
I m trying to pass a parameter to the below Store Procedure

CREATE PROCEDURE [Sp_ConfigureCourses]
@Colleague_cartNumber varchar(50)

AS
Select * FROM CarterCourses WHERE @Colleague_cartNumber <>1 order by CourseName
GO

As you can see here @Colleague_cartNumber is the column Name
What datatype should i pass the parameter as.
If i pass as int or nvarchar i get errors.(asp.net application)
Please help

raymondpeacock
Constraint Violating Yak Guru

367 Posts

Posted - 2004-06-22 : 11:28:52
The datatype of the parameter isn't the problem here. The parameter isn't being resolved at execution to evaluate to the column name. You could try dynamic SQL something like this

DECLARE @cmd VARCHAR(1000)
SET @cmd = 'SELECT * FROM CarterCourses WHERE ' + @Colleague_CartNumber + ' <> 1 ORDER BY CourseName'
EXEC (@cmd)



Raymond
Go to Top of Page

dnagahawatte
Starting Member

24 Posts

Posted - 2004-06-22 : 11:56:17
sweet
Thanks a lot for the quick reply...
Go to Top of Page
   

- Advertisement -