473,809 Members | 2,718 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Querying a column with brackets in its name

Hi All,
I was hoping someone has experienced this before, I'm having trouble
googling this. I'm working with a poorly writtend database that has some
fields named as such: MTIC_PROD_VEND[ 1]

I do not have the option to rename this field but I do need to retreive data
from it with SQL. I've tried a suggestion of [MTIC_PROD_VEND[ 1]]] and that
doesn't seem to work, it may be because the 1 has a space leading it. Does
anyone happen to have any suggestion to try to work around this? Any
assistance would be greatly appreciated. Thanks.

Regards,
Stephan
Mar 16 '06 #1
2 7905
> I was hoping someone has experienced this before, I'm having trouble
googling this. I'm working with a poorly writtend database that has some
fields named as such: MTIC_PROD_VEND[ 1]
`MTIC_PROD_VEND[ 1]`
I do not have the option to rename this field but I do need to retreive data
from it with SQL. I've tried a suggestion of [MTIC_PROD_VEND[ 1]]] and that
doesn't seem to work, it may be because the 1 has a space leading it. Does
anyone happen to have any suggestion to try to work around this? Any
assistance would be greatly appreciated. Thanks.


If a table or field name has wierd characters in it, enclose it in
backquotes. I'm not real sure how to deal with the situation where
a table name has both backslashes and backquotes in its name, but
hopefully that will never come up.

Gordon L. Burditt
Mar 16 '06 #2
"Usulnet" <gd**@sbcglobal .net> wrote in message
news:JR******** ***********@new ssvr21.news.pro digy.com...
I'm working with a poorly writtend database that has some
fields named as such: MTIC_PROD_VEND[ 1]


You need to use "delimited identifiers". This is a SQL feature that allows
us to use SQL reserved words and special characters in the names of tables
and fields.

MySQL uses backticks by default to delimit identifiers:

SELECT `MTIC_PROD_VEND[ 1]` FROM . . .

The ANSI SQL standard uses double-quotes to delimit identifers:
MySQL supports this too, if you set the ANSI_QUOTES SQL mode.
See http://dev.mysql.com/doc/refman/5.0/...-sql-mode.html

SET GLOBAL SQL_MODE = 'ANSI_QUOTES';
SELECT "MTIC_PROD_ VEND[ 1]" FROM . . .

Microsoft SQL Server uses square brackets to delimit identifiers.
See http://msdn2.microsoft.com/en-US/library/ms176027.aspx

Regards,
Bill K.
Mar 16 '06 #3

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

Similar topics

7
11923
by: CharlesEF | last post by:
Hi All, I have run into another problem that is eating my lunch. Should be simple but I am having one heck of a time. Please look at this SELECT statement: SELECT FROM States WHERE ] = "US"; is the SQL column name (because it sarts with 2?). As the statement is shown I get the error message: Unclosed quotation mark before the character
5
2379
by: Shane | last post by:
I wonder if someone has any ideas about the following. I am currently producing some reports for a manufacturing company who work with metal. A finished part can contain multiple sub-parts to make up the finished part. The sub-parts can also be made up of sub-parts and those sub-parts can also be made up of sub-parts etc etc. All parts are contained within the same table and I have a seperate table
9
7433
by: Jack | last post by:
In the control source of a textbox, is there a way to refer to a column of a combobox? For example: =.Column(2) Thanks, Jack
17
3839
by: Benoit Martin | last post by:
I'm working on a project in VB.net connecting to a SQL Server 2000 database that I can't modify I created a dataset with a schema identical to the DB. When trying to update the DB from the dataset using the dataAdapter.update sub, I get an error. The problem seems to be that one of the fields was named 'desc' which is a reserved word for SQL. I've been able to work around this design flaw 'till now but it looks like the update sub can't...
4
10960
by: Usulnet | last post by:
Hi All, I was hoping someone has experienced this before, I'm having trouble googling this. I'm working with a poorly writtend database that has some fields named as such: MTIC_PROD_VEND I do not have the option to rename this field but I do need to retreive data from it with SQL. I've tried a suggestion of ]] and that doesn't seem to work, it may be because the 1 has a space leading it. Does anyone happen to have any suggestion to...
6
6545
by: blue875 | last post by:
A tale of two queries: One query looks like this, and runs fine. We'll call this the "Customer1 query": SELECT Customer1 overall.*, IIf(IsNull(.),0,1) AS IsField, IIf(IsNull(.),0,1) AS IsStaff FROM ( LEFT JOIN ON .=.) LEFT JOIN
4
2282
by: onecorp | last post by:
I have a SQL table comprised of 31 columns. The first column is simply an id column, the next 30 columns are labelled ,.... The numerical columns have a tinyint type and the data stored is either 1 or null. I wish to count the number of times a one appears in one column simultaneously with another column: eg count the number of times 1 appears in column and 1 also appears in column in the same row:
7
1929
by: decren | last post by:
Hello, I have a table with an add-row setup. The table has several columns but I only need to calculate COLUMN FOUR. The results go to a textbox via a button. My code is..... function sumup() { document.getElementById("Table1") column = document.getElementsByTagName("colFour"); document.myForm.tbTotal.value = column; } ..... <TABLE NAME="Table1" id="Table1">
5
25589
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
1
3410
by: christianlott1 | last post by:
I want to provide users with an interface to create a custom merge (all in Access, not Word). User will put in a set of brackets ("<>") in a memo field and when they click the merge button it will grab the fields listed in a tabular subform and merge it with their memo text. I was able to retrieve the code to list the column names of a table. I constructed the code to iterate the tabular subform rows and replace the brackets with the row...
0
10639
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
10376
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
10383
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,...
0
10120
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7661
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
5550
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
5688
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4332
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
2
3861
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.