472,331 Members | 1,521 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,331 software developers and data experts.

pass Column Name using Parameter in SQL Statement...

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

Oct 19 '07 #1
5 5143
(ra********@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, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Oct 19 '07 #2
>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.

Oct 19 '07 #3
On Oct 19, 9:06 am, --CELKO-- <jcelko...@earthlink.netwrote:
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.
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.

Oct 24 '07 #4
<pa***********@gmail.comwrote in message
news:11**********************@y27g2000pre.googlegr oups.com...
On Oct 19, 9:06 am, --CELKO-- <jcelko...@earthlink.netwrote:
>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.

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.
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."

:-)

>


--
Greg Moore
SQL Server DBA Consulting Remote and Onsite available!
Email: sql (at) greenms.com http://www.greenms.com/sqlserver.html
Oct 24 '07 #5
Or.... Practical SQL Solutions in the Real World.

--
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]
"Greg D. Moore (Strider)" <mo****************@greenms.comwrote in message
news:13*************@corp.supernews.com...
<pa***********@gmail.comwrote in message
news:11**********************@y27g2000pre.googlegr oups.com...
>On Oct 19, 9:06 am, --CELKO-- <jcelko...@earthlink.netwrote:
>>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.

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.

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."

:-)

>>

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

Oct 28 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: deko | last post by:
I need a way to create a table with a programmatically defined name. I have a Make Table query that will create the table with the name that I put...
7
by: Zlatko Matić | last post by:
Let's assume that we have a database on some SQL server (let it be MS SQL Server) and that we want to execute some parameterized query as a...
1
by: imauser | last post by:
I have a database(PostgreSQL) table(about 70k rows).I am developing an ASP webpage and there is a list-box on it which contains the name of the...
5
by: Ken | last post by:
I'm trying to run a loop to capture column property information from a table in my datasource. Can anybody see where this is going wrong? Dim...
12
by: ArunDhaJ | last post by:
Hi Friends, Is it possible to pass a table as a parameter to a funtion. whos function declaration would look some thing like this.... ALTER...
13
by: =?Utf-8?B?UGV0ZXI=?= | last post by:
I want to create a new column in a datatable from two existing columns. I have no problem to create the new column using the datatable.columns.add...
14
by: bill | last post by:
Can someone please show me an example of passing a string value into an sql statement in vb 2005? Something like this is what I'm after: Dim...
1
by: ajax.sam | last post by:
hi all, i got 2 questions! i want to do these: 1. select @col1 from some_table where <some_conditions>; I can pass parameters by using...
0
by: bharathreddy | last post by:
This article will explain you how to check weather a column already exists in a table before you add the column to the table using alter command. ...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.