Hola chicos…
Tengo un problemita con cierto query nuevo que me están pidiendo para un reporte de SAP B1. La cuestión es que el Query en sí funciona bien en SQL. Me lo llevo a SAP B1 y funciona, pero al momento de ponerle más de 1 solicitud de variable me sale error…
Antes de explicar este es el Query:
SELECT
T4.U_OFICINA as 'ID OFICINA',
T2.U_NUM_POLIZA AS 'NUM POLIZA',
T4.U_EMPRESA 'NUM EMPRESA',
'PAX' as 'PAX',
T2.U_PRIMA_SEGURO AS 'PRIMA',
T2.U_FECH_I_RENOV AS 'VIGENCIA DESDE',
T2.U_FECH_FIN_RENOV AS 'VIGENCIA HASTA',
T2.DocTotal AS 'IMPORTE',
T4.CardName AS 'NOMBRE',
'TIPO EMPRESA' AS 'TIPO EMPRESA',
"PAGO A" = CASE
WHEN (T0.TrsfrAcct) is not null and T0.TrsfrAcct <> '' then
(Select top 1 accntntcod from OACT where OACT.AcctCode = T0.TrsfrAcct)
WHEN T0.CashAcct is not null and T0.CashAcct <> '' then
(Select top 1 accntntcod from OACT where OACT.AcctCode = T0.CashAcct)
WHEN T0.CheckAcct is not null and T0.CheckAcct <> '' then
(Select top 1 accntntcod from OACT where OACT.AcctCode = T0.CheckAcct)
else
'N/A'
End,
convert (nvarchar(10),T0.DocDate,103) AS 'FECHA DEP',
"NUM DE CHEQUE O TRANS" = case
WHEN T0.CheckAcct is not null and T0.CheckAcct <> '' then
str(T5.CheckNum)
WHEN (T0.TrsfrAcct) is not null and T0.TrsfrAcct <> '' then
T0.TrsfrRef
WHEN T0.CashAcct is not null and T0.CashAcct <> '' then
T0.CounterRef
else
'SIN REF'
end,
'BANCO' AS 'BANCO',
T3.BaseRef AS 'FOLIO A COBRO',
T2.DocNum AS 'FOLIO RRS',
T0.DocNum AS 'FOLIO PAGO',
T4.U_RESPONSABLE AS 'RESPONSABLE',
'FOLIO FICHA' AS 'FOLIO FICHA',
T0.DocTotal AS 'TOTAL',
T0.docdate as 'FECRANGO'
FROM ORCT T0
INNER JOIN RCT2 T1 ON T0.[DocEntry] = T1.[DocNum]
INNER JOIN OINV T2 ON T1.DocEntry = T2.DocNum
INNER JOIN OCRD T4 ON T0.[CardCode] = T4.[CardCode]
INNER JOIN INV1 T3 ON T2.[DocEntry] = T3.[DocEntry]
LEFT OUTER JOIN RCT1 T5 ON T0.[DocEntry] = T5.[DocNum]
WHERE
T4.[U_OFICINA] = [%0] and
T0.[DocDate] >= [%1] and
T0.[DocDate] <= [%2]
Ok, ahora si en el Where al final solo dejo el T4.U_Oficina = [%0] el query funciona a la perfección en lo que agrego los otros 2 me empieza a arrojar error:
“1). [Microsoft][SQL Server Native Client 11.0][SQL Server]Incorrect syntax near the keyword ‘FOR’.
2). [Microsoft][SQL Server Native Client 11.0][SQL Server]Statement ‘’ (SWEI) (s) could not be prepared.”
Cuando en realidad no existen ningún “FOR” en la consulta. Me leí varios temas aquí y los he intentado. Les coloco aquí lo que ya he probado:
Ya intenté de colocar:
DECLARE @FechaInicial AS DATETIME
DECLARE @FechaFinal AS DATETIME
DECLARE @Oficina as Varchar
SET @FechaInicial = CONVERT(DATETIME, '[%1]', 112)
SET @FechaFinal = CONVERT(DATETIME, '[%2]', 112)
Set @oficina = [%0]
...
Where
T4.[U_OFICINA] = @Oficina and
T0.[DocDate] >= @Fechainicial and
T0.[DocDate] <= @Fechafinal
Y nada…
Alguna otra idea? o algo que me esté faltando?