Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 20-10-2008
Member
 
Join Date: Jul 2008
Posts: 15
MSSQL Field name with spaces

I'm not sure if this is the right place to ask about this so please move to the correct section if it's not.

I am trying to query a MSSQL (SQL Express) database using PHP but am having trouble retrieving the data from a field with a space in it.

I've tried using " or ' or even ` but none of them seem to work. Can someone help me out?

$query = "SELECT Field1, Field2, Field3, 'Field 4'";

Field 4 returns no data.

Any help would be appreciated. Thanks
Reply With Quote
  #2  
Old 21-10-2008
Member
 
Join Date: Oct 2008
Posts: 6
Try this:

$query = "SELECT Field1, Field2, Field3, [Field 4]";

Note the [] on field 4
Reply With Quote
  #3  
Old 21-10-2008
Member
 
Join Date: Dec 2007
Posts: 1,592
Actually, the "[" syntax is not the only one that can be used with MS SQL. It also supports the SQL Standard defined delimited identifiers. In the standard, normal identifiers (e.g. column/table names) have the same rules as Java/C variables. (with the exception that they are case insensitive...) If you want/need to use characters outside of this set, you need to use delimited identifiers. These have the Standard defined syntax of "My Table!" (double quote's included). Delimited identifiers ARE case sensitive. So, the standards version id of a column in your table would be written like: "Time after".time_col

AFAIK, this syntax is pretty widely supported by the major DB players. Getting Torque to recognize and map the Java names to the real names is going to be a hard thing. One thing that *might* work out of the box is the various ant tasks. If you define your names in the XML to include the double quotes, the SQL generated by these should work. To be complete, I guess you could also try to generate the code with the delimited cases and then "fix up" the classes that don't compile. You'd also have to make sure the Map classes used the correct strings as well. Not very maintainable but...
Reply With Quote
  #4  
Old 21-10-2008
Member
 
Join Date: Mar 2008
Posts: 382
Hi,
The following thread link may help you to retrieve the field you expected.

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=95792

http://www.osix.net/modules/article/?id=400

cheers
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "MSSQL Field name with spaces"
Thread Thread Starter Forum Replies Last Post
Specifications of CSV to MSSQL Loader Kalanidhi Windows Software 5 14-02-2010 02:31 AM
How to improve compatibility with MSSQL and ACCESS Alondra Software Development 5 13-02-2010 03:58 AM
How to get more security from MSSQL Chakradev Software Development 5 13-02-2010 03:29 AM
Multi Field value field in Microsoft Access Erubiel Windows Software 3 20-11-2009 12:55 AM
Mssql$vaio_vedb.sys McGrawh Software Development 3 15-06-2009 03:27 PM


All times are GMT +5.5. The time now is 03:19 AM.