T sql

  • Hi Guys,

    how can I use words reserved in selected t sql, as Select GROUP, DESC, EXTERNAL, etc ..., i use thems with a linked server, i have a error message:

    OLE DB provider "MSDASQL" for linked server "TTS_TEST_VAC" returned message "[Marxmeier][SQL/R ODBC Server]37000 - Unexpected symbol (#1)

    syntax error near "["

    Unexpected symbol or invalid SQL/R language statement.

    ".

    Thank

  • Could you post the code that is causing the issue?

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

  • eboucicaut (7/17/2015)


    Hi Guys,

    how can I use words reserved in selected t sql, as Select GROUP, DESC, EXTERNAL, etc ..., i use thems with a linked server, i have a error message:

    OLE DB provider "MSDASQL" for linked server "TTS_TEST_VAC" returned message "[Marxmeier][SQL/R ODBC Server]37000 - Unexpected symbol (#1)

    syntax error near "["

    Unexpected symbol or invalid SQL/R language statement.

    ".

    Thank

    Not much detail here but I think you have column names that are sql reserved words? This is a bad decision because it causes lots of pain when querying. It also can easily generate some serious confusion if the word is a column or the t-sql keyword. If you can't change the column names you will have to wrap them in square brackets.

    Select [GROUP], [DESC], [EXTERNAL]

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • Sean Lange (7/17/2015)


    eboucicaut (7/17/2015)


    Hi Guys,

    how can I use words reserved in selected t sql, as Select GROUP, DESC, EXTERNAL, etc ..., i use thems with a linked server, i have a error message:

    OLE DB provider "MSDASQL" for linked server "TTS_TEST_VAC" returned message "[Marxmeier][SQL/R ODBC Server]37000 - Unexpected symbol (#1)

    syntax error near "["

    Unexpected symbol or invalid SQL/R language statement.

    ".

    Thank

    Not much detail here but I think you have column names that are sql reserved words? This is a bad decision because it causes lots of pain when querying. It also can easily generate some serious confusion if the word is a column or the t-sql keyword. If you can't change the column names you will have to wrap them in square brackets.

    Select [GROUP], [DESC], [EXTERNAL]

    I have to agree, but sometimes your stuck with what the developers have done. I am trying to get in the habit of always enclosing column names in square brackets in my dynamic SQL I write. Its fun when dynamic SQL that worked in SQL Server 2005 now fails in SQL Server 2008 because of a change in reserved words.

  • Lynn Pettis (7/17/2015)


    Sean Lange (7/17/2015)


    eboucicaut (7/17/2015)


    Hi Guys,

    how can I use words reserved in selected t sql, as Select GROUP, DESC, EXTERNAL, etc ..., i use thems with a linked server, i have a error message:

    OLE DB provider "MSDASQL" for linked server "TTS_TEST_VAC" returned message "[Marxmeier][SQL/R ODBC Server]37000 - Unexpected symbol (#1)

    syntax error near "["

    Unexpected symbol or invalid SQL/R language statement.

    ".

    Thank

    Not much detail here but I think you have column names that are sql reserved words? This is a bad decision because it causes lots of pain when querying. It also can easily generate some serious confusion if the word is a column or the t-sql keyword. If you can't change the column names you will have to wrap them in square brackets.

    Select [GROUP], [DESC], [EXTERNAL]

    I have to agree, but sometimes your stuck with what the developers have done. I am trying to get in the habit of always enclosing column names in square brackets in my dynamic SQL I write. Its fun when dynamic SQL that worked in SQL Server 2005 now fails in SQL Server 2008 because of a change in reserved words.

    I hear you on being stuck. We have plenty of rubbish that is far worse than this for sure. Often times the reserved words are easily avoided by using a non-ambiguous column name. Instead of things like Group it makes more sense to have something like ProgramGroup or something like that. Of course this isn't a great example since that should most likely be a foreign key. 😉

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • Hi,

    Maybe you also check the current QUOTED_IDENTIFIER set in the user connection configuration.

    SET QUOTED_IDENTIFIER (Transact-SQL)

    https://msdn.microsoft.com/en-us/library/ms174393.aspx

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply