You are here: Re: pass Column Name using Parameter in SQL Statement... « MsSQL Server « IT news, forums, messages
Re: pass Column Name using Parameter in SQL Statement...

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация