Results 1 to 7 of 7

Thread: SQL Statement: "top" field

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2001
    Posts
    1,140

    SQL Statement: "top" field

    I'm using SQL Server, and I get a syntax error on a syntax error on a statement that uses "top" as a field name. But the table has a field named top, so how I do SELECT it?

    VB Code:
    1. 'This gives me an error
    2. SQL = "SELECT myField, top, myOtherField FROM myTable"
    Travis, Kung Foo Journeyman
    As always, RTFM.

    WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
    Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
    YBMS, but Mozilla doesn't.

  2. #2
    Hyperactive Member
    Join Date
    Jan 2000
    Location
    Edinburgh, Scotland
    Posts
    272
    What about (not certain - but worth a try)

    SQL = "SELECT myField, [top], myOtherField FROM myTable"

    or

    SQL = "SELECT myField, top.myTable, myOtherField FROM myTable"

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2001
    Posts
    1,140
    No luck. I also tryed...

    VB Code:
    1. SQL = "SELECT myField, myTable.top, myOtherField FROM myTable"
    2. SQL = "SELECT myField, myTable.[top], myOtherField FROM myTable"
    3. SQL = "SELECT (myField, myTable.top, myOtherField) FROM myTable"
    4. SQL = "SELECT (myField, myTable.[top], myOtherField) FROM myTable"
    5. SQL = "SELECT (myField, top, myOtherField) FROM myTable"
    6. SQL = "SELECT (myField, [top], myOtherField) FROM myTable"
    Travis, Kung Foo Journeyman
    As always, RTFM.

    WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
    Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
    YBMS, but Mozilla doesn't.

  4. #4
    Hyperactive Member
    Join Date
    Jan 2000
    Location
    Edinburgh, Scotland
    Posts
    272
    Sorry then! It's bugging me now - so if I find something when I get to work tomorrow, I'll post the answer.

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2001
    Posts
    1,140
    I got it to work.

    Code:
    SQL = "SELECT myTable.myField, myTable.[top], myTable.myOtherField FROM myTable"
    Travis, Kung Foo Journeyman
    As always, RTFM.

    WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
    Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
    YBMS, but Mozilla doesn't.

  6. #6
    Fanatic Member Gary.Lowe's Avatar
    Join Date
    May 2000
    Location
    In my sphere of influence
    Posts
    621
    Top is a reserved word in SQL 'SELECT TOP 5...'
    It is always best to try and add a prefix if you need to use a word that is also a reserved word. Same as naming a field 'Date' SQL can get confused
    Gary Lowe
    VB6 (Enterprise) SP5
    ADO 2.6
    SQL Server 7 SP3

    OK I know my spelling and grammer is crap so don't quote me on it!

    To err is human to take the P! is only natural !!

    Click on the top section of image for Marcus Miller website and bottom section of image for 'Run For Cover' sound clip


  7. #7
    Hyperactive Member
    Join Date
    Jan 2000
    Location
    Edinburgh, Scotland
    Posts
    272
    CiberTHuG, it looks like you just about had every permutation, and I'm glad you finally cracked it!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width