Results 1 to 4 of 4

Thread: MSSQL Field name with spaces

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

  2. #2
    Join Date
    Oct 2008
    Posts
    6
    Try this:

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

    Note the [] on field 4

  3. #3
    Join Date
    Dec 2007
    Posts
    1,599
    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...

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

Similar Threads

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

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,648,191.16615 seconds with 17 queries