Código SQL:
Ver original
DECLARE [Q]SQL NVARCHAR(MAX) SET [Q]SQL = N'SELECT * FROM ( SELECT b.cardcode,b.cardname,b.docnum,day(docduedate) as [day],Delivrdqty FROM empresafinal.dbo.RDR1 A inner join empresafinal.dbo.ORDR B on A.docentry=B.docentry inner join empresatest.dbo.OCRD C on c.cardcode=b.cardcode where B.canceled=''N'' and ((b.docstatus=''C'' and b.invntSttus=''C'') or (b.docstatus=''C'' and b.invntSttus=''O'')) and b.docduedate>=convert(datetime,' + [Q]lfecha_inicial + ') and b.docduedate<=convert(datetime,' + [Q]lfecha_final + ') and (a.whscode<>''LubAlma'' and a.whscode<>''01'') ) pvt PIVOT (SUM(Delivrdqty) FOR [day] IN (' + [Q]DiaPVT + ')) AS Child ORDER by Cardcode' EXECUTE sp_executesql [Q]SQL
he reemplazado el simbolo "arroba" por [Q] junto a las variables.
El contenido de las variables es según el depurador:
[Q]lfecha_inicial =2009-11-01 00:00:00.000
[Q]lfecha_final=2009-11-30 00:00:00.000
De antemano gracias.