problems wiht a query

  • Hi every one, I have a little problem and I don´t know why is happening.

    We have a stored procedure that we create the query sentence like a string and then execute it. We use this sp in 6 different databases and in 5 of them it just work fine but in the last one it marks an error, I identify that is when we use:

    sp, 'Ob_L%0','MBM'

    inside the sp we use this:

    @strsql = 'SELECT distinct field FROM table

    WHERE field LIKE "Ob_L%0"'

    exec (@strsql)

    and it gives me this message:

    Server: Msg 207, Level 16, State 3, Line 1

    Invalid column name 'Ozb_L%0'.

    but if = run the same sentence, sp in one of the other databases works just fine.

    Can someone help me understandying what is happening, or what can I do.

    Thanks a lot

    Ana


    Ana

  • Sounds like a problem with quoted_identifier.

    Andy

    http://qa.sqlservercentral.com/columnists/awarren/

  • Then use simple quotes in you @strsql.

    (to include a simple quote in a simple quote delimited string, type it twice

    @strsql = 'SELECT distinct field FROM table

    WHERE field LIKE ''Ob_L%0'' '

    )

    The posible differences o fbehavior:

    a) The default config in server #6 difers from the others, check the Connections tab in the properties tab.

    b) If using ODBC check delimiters for the conection.

    c) Is using Query Analizer, check Current Connection Options.

    d) If can't avoid differences, include a SET statement in your store proc.

    quote:


    Hi every one, I have a little problem and I don´t know why is happening.

    We have a stored procedure that we create the query sentence like a string and then execute it. We use this sp in 6 different databases and in 5 of them it just work fine but in the last one it marks an error, I identify that is when we use:

    sp, 'Ob_L%0','MBM'

    inside the sp we use this:

    @strsql = 'SELECT distinct field FROM table

    WHERE field LIKE "Ob_L%0"'

    exec (@strsql)

    and it gives me this message:

    Server: Msg 207, Level 16, State 3, Line 1

    Invalid column name 'Ozb_L%0'.

    but if = run the same sentence, sp in one of the other databases works just fine.

    Can someone help me understandying what is happening, or what can I do.

    Thanks a lot

    Ana


  • Or try this:

    @strsql = 'SELECT distinct field FROM table

    WHERE field LIKE '+''''+'Ob_L%0'+''''

    exec (@strsql)

Viewing 4 posts - 1 through 3 (of 3 total)

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