Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
DB Engine
SQL ServerMSDESQL Server CE
Services
Analysis (Data Mining)Analysis (OLAP)DTSIntegration ServicesNotification ServicesReporting Services
Programming
CLRConnectivitySQLXML
Other Technologies
ClusteringEnglish QueryFull-Text SearchReplicationService Broker
General
Data WarehousingPerformanceSecuritySetupSQL Server ToolsOther SQL Server Topics
DirectoryUser Groups
Related Topics
MS AccessOther DB ProductsMS Server Products.NET DevelopmentVB DevelopmentJava DevelopmentMore Topics ...

SQL Server Forum / General / Other SQL Server Topics / October 2007

Tip: Looking for answers? Try searching our database.

pass Column Name using Parameter in SQL Statement...

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
raghutumma@gmail.com - 19 Oct 2007 06:37 GMT
Hi,

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???

Thanx in Advance,
Regards,
Raghu...
Erland Sommarskog - 19 Oct 2007 08:11 GMT
> I am trying to Pass Column Name(FieldName) using Parameter in SQL
> Statement... But i am getting error...
[quoted text clipped - 9 lines]
>
> 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

Signature

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

--CELKO-- - 19 Oct 2007 15:06 GMT
>> how can i pass Column name using parameter?  <<

You don't do this; it is bad programming.  A well-designed module of
code returns a predictable result.  What you have is what I call a
"Britney Spears, Squids and Automobiles" module, since it can return
anything of any data type!

Get a book on basic Software Engineering and read about coupling and
cohesion before you do any more programming in any language.
paulschultz54@gmail.com - 24 Oct 2007 03:03 GMT
> >> how can i pass Column name using parameter?  <<
>
[quoted text clipped - 5 lines]
> Get a book on basic Software Engineering and read about coupling and
> cohesion before you do any more programming in any language.

Maybe they weren't responsible for the database design, but are being
asked query from it due to business requirements or maybe it's not a
critical application and it's was easier to load a flat file into
Access than to design a proper normalized database.  Regardless, it's
a legitimate question (as are your concerns about unpredictable
results), but to assume that Raghu doesn't know basic Software
Engineering is rude.
Greg D. Moore (Strider) - 24 Oct 2007 12:37 GMT
>> >> how can i pass Column name using parameter?  <<
>>
[quoted text clipped - 13 lines]
> results), but to assume that Raghu doesn't know basic Software
> Engineering is rude.

You know, Joe has written several books, SQL for Smarties comes to mind.

However, one book that I doubt he'll ever be asked to write is "Joe Celko's
Guide to Winning Friends and Influencing People."

:-)

Signature

Greg Moore
SQL Server DBA Consulting           Remote and Onsite available!
Email: sql  (at)  greenms.com          http://www.greenms.com/sqlserver.html

Tony Rogerson - 28 Oct 2007 09:18 GMT
Or.... Practical SQL Solutions in the Real World.

Signature

Tony Rogerson, SQL Server MVP
http://sqlblogcasts.com/blogs/tonyrogerson
[Ramblings from the field from a SQL consultant]
http://sqlserverfaq.com
[UK SQL User Community]

>>> >> how can i pass Column name using parameter?  <<
>>>
[quoted text clipped - 20 lines]
>
> :-)
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.