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)
 Passing a column name as a variable

Author  Topic 

srad
Starting Member

39 Posts

Posted - 2001-08-15 : 10:38:03
Hello this is my first post so i hope that i supply you with enough information.

I am trying to write a sp that selects from one of two cols depending on the length
of the input param. The variable @codetype stores the name of the column that i want
to select from. Here's the snippit of code that's not working..

declare @codetype char(8)
select @codetype = 'column name'
SELECT COUNT([column name])
FROM [table name]
WHERE @codetype = value

i get the following error
Server: Msg 245, Level 16, State 1, Line 3
Syntax error converting the varchar value 'column name' to a column of data type int.

When i add a print statement to the code it returns the name of the column i want to
query from.

Hope you can help.



   

- Advertisement -