none
error message might related to '' RRS feed

  • Question

  • Hi,

    when I execute my script, I get error. Could you please help me?

    create table aa
    (value varchar(10))
    insert into aa values ('hhhh''hhhh'),('hhhh')

    select * from aa
    --value
    ------------
    --hhhh'hhhh
    --hhhh

    declare @sql varchar(max)
    set @sql ='select * from aa where value=''hhhh''hhhh'''
    print(@sql)
    exec(@sql)

    error message:
    Msg 102, Level 15, State 1, Line 11
    Incorrect syntax near 'hhhh'.
    Msg 105, Level 15, State 1, Line 11
    Unclosed quotation mark after the character string ''.

    Thursday, October 17, 2019 7:51 AM

Answers

  • Hi KeithBucholtz,

    Welcome to SQL Server > Transact-SQL Forum.

    I will advice you to use print(@sql) to check your query. If you use it , you will find the error easily.

    Please check following script .

    create table aa 
    (value varchar(10))
    insert into aa values ('hhhh''hhhh'),('hhhh')
    
    select * from aa
    --value
    ------------
    --hhhh'hhhh
    --hhhh
    
    ------your script
    declare @sql varchar(max)
    set @sql ='select * from aa where value=''hhhh''hhhh'''
    print(@sql)
    /*
    select * from aa where value='hhhh'hhhh'
    */
    
    
    go
    declare @sql varchar(max)
    set @sql ='select * from aa where value=''hhhh''''hhhh'''
    print(@sql)
    /*
    select * from aa where value='hhhh''hhhh'
    */
    exec(@sql)
    /*
    value
    ----------
    hhhh'hhhh
    */
    
    

    Best Regards,

    Rachel


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, October 17, 2019 8:05 AM

All replies

  • Hi KeithBucholtz,

    Welcome to SQL Server > Transact-SQL Forum.

    I will advice you to use print(@sql) to check your query. If you use it , you will find the error easily.

    Please check following script .

    create table aa 
    (value varchar(10))
    insert into aa values ('hhhh''hhhh'),('hhhh')
    
    select * from aa
    --value
    ------------
    --hhhh'hhhh
    --hhhh
    
    ------your script
    declare @sql varchar(max)
    set @sql ='select * from aa where value=''hhhh''hhhh'''
    print(@sql)
    /*
    select * from aa where value='hhhh'hhhh'
    */
    
    
    go
    declare @sql varchar(max)
    set @sql ='select * from aa where value=''hhhh''''hhhh'''
    print(@sql)
    /*
    select * from aa where value='hhhh''hhhh'
    */
    exec(@sql)
    /*
    value
    ----------
    hhhh'hhhh
    */
    
    

    Best Regards,

    Rachel


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, October 17, 2019 8:05 AM
  • Remove the EXEC and Review the PRINT result; there are 2 hyphen to less

    set @sql ='select * from aa where value=''hhhh''''hhhh'''


    Olaf Helper

    [ Blog] [ Xing] [ MVP]

    Thursday, October 17, 2019 8:05 AM
  • Hi ,

     

    I am writing to follow up this thread with you. Have you solved your issue? If you have solved your issue ,in order to close this thread, please kindly mark helpful replies as answers. By doing so, it will benefit all community members who are having this similar issue.  Your contribution is highly appreciated.

     

    Best Regards,

    Rachel


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, October 21, 2019 6:59 AM
  • The codes helped me a lot. I have solved the issue already. Thanks xx.
    Tuesday, October 22, 2019 5:40 AM