Posted by Erland Sommarskog on 10/19/07 07:11
(raghutumma@gmail.com) writes:
> I am trying to Pass Column Name(FieldName) using Parameter in SQL
> Statement... But i am getting error...
>
> how can i pass Column name using parameter???
>
> Example:
>
> in table i have fieldname ECountry...
>
> Select @FName='ECountry'
> Select @FName from Table...
>
> How it works???
Why would you do it in the first place? Given a well-designed database,
the request does not make very much sense. But if you have a less well-
designed database, you need to do:
SELECT CASE @paramname
WHEN 'thatfield' THEN thatfield
WHEN 'thisfield' THEN thisfield
WHEN 'leftfield' THEN leftfield
END
FROM tbl
--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
[Back to original message]
|