how to put the quotes correctly?

2

I have the following code which gives me the error shown, it seems to me that I am misplacing some quotes.

Declare '@Cuenta Varchar(25),@Fecha Varchar(10),@Moneda Varchar(3),@User Varchar(20)'
Declare '@NomTabla Varchar(60)'  


    SET @User = 'Usuario'
    SET @Cuenta ='190106010105'
    SET @Fecha ='20170812'
    SET @Moneda = 'SOL'
    SET @NomTabla = '##RptMayorDetalle' + @User

    EXEC ('SELECT * FROM Contabilidad..Comprobante WHERE FOLIO LIKE'+ @Fecha+' + ''%''')

I get the error:

  

Msg 4145, Level 15, State 1, Line 1

A non-Boolean expression was specified in a context where a condition was expected, close to LIKE20170812 .

    
asked by CeciliaMa 23.09.2017 в 00:46
source

1 answer

3

You can use ''' (3 apostrophes) or with CHAR(39)

Your query would remain like this

opt1:

EXEC ('SELECT * FROM Contabilidad..Comprobante WHERE FOLIO LIKE '''+ @Fecha + '%''')

opc 2:

EXEC ('SELECT * FROM Contabilidad..Comprobante WHERE FOLIO LIKE ' + CHAR(39) + @Fecha + '%' + CHAR(39))

I hope you help, greetings

    
answered by 23.09.2017 / 01:00
source