473,856 Members | 1,708 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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='ECountr y'
Select @FName from Table...

How it works???

Thanx in Advance,
Regards,
Raghu...

Oct 19 '07 #1
5 5208
(ra********@gma il.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='ECountr y'
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****@sommarsk og.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...@eart hlink.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.goo glegroups.com.. .
On Oct 19, 9:06 am, --CELKO-- <jcelko...@eart hlink.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.co mwrote in message
news:13******** *****@corp.supe rnews.com...
<pa***********@ gmail.comwrote in message
news:11******** **************@ y27g2000pre.goo glegroups.com.. .
>On Oct 19, 9:06 am, --CELKO-- <jcelko...@eart hlink.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
7206
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 in the query, but I don't know how to (or if I can) use a function to pass the table name into the query. Here is the basic form of the Mke Tble query: SELECT TxDate, Amount, Tx_ID, TxAcctName, INTO FROM tblTxJournal;
7
21646
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 pass.through query. How can we pass parameters to the server ? Is it possible to use parameters in pass-through queries ? An additional question: Is it possible to connect to a database on MySQL or PostgreSQL using ADO ? Is it possible to execute pass-through queries with parameters, using ADO...
1
4566
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 columns of that table. User selects the column name from that box and a query is sent to the database. The data from that column should be returned to the user. Now the problem is that, I have seen the 'SELECT' statements with the exact column name written in it.But in my case the column name is...
5
25596
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 tbl As New DataTable Dim col As DataColumn Dim x As Integer Dim colName(99) As String Dim colType(99) As String cn.Open() tbl = cn.GetSchema("Orders") 'Orders is a table in the
12
4652
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 FUNCTION TempFunction (@TempTable TABLE, @nPId INT) my problem is: i have to access a temporary table created in an SP in a function
13
2612
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 method. The problem is the value of the new column may become system.dbnull since one of the two existing columns may have system.dbnull. How can I fix it so the new column will get the value of the other column even the other column is system.dbnull?
14
1890
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 sqlButton1 As String = "Select * from tblAssets where Asset_Tag = Me.cboAsset.Text" Thank you, Bill
1
1728
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 Parameters.Add for <some_conditionsbut not for the @col1. How do i do that? How do i pass column names as parameters? 2. select * from @table; How can i pass a table name as a parameter? Thanks,
0
6458
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. Using the system tables you can check to see weather a column already belongs to a specific table. SYSCOLUMNS is the system table which stores all the table columns information, from this column you can check weather a specific column exists in a specific table. ...
0
9755
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11048
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10692
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10770
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7928
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7084
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5754
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5954
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4567
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.