Мой набор данных работает нормально в SSMS, но когда я пытаюсь вставить его в SSRS, я получаю ошибку Incorrect syntax near the keyword 'CONVERT' (Error 156)
Причиной, по которой я использовал функцию, было разделение строки для получения полей Attention, Address 1 и Address2. Функция объединяется с помощью перекрестного применения [dbo]. [Split3].Я использую среду SQL Server 2008 R2.
select
a.fsono,
a.fcustno,
Replace(max(a.Attention), 'ATTN: ', '') As Attention,
MAX(a.Address1) AS Address1,
MAX(a.Address2) AS Address2,
a.ShipCode,
a.Item,
a.Qty,
a.Descr,
a.fordername,
a.fcfromno,
a.fcfromtype,
a.min_finumber
FROM (
SELECT
soitem.fsono,
somast.fcustno,
CAST(somast.fackmemo as CHAR(35)) as ShipCode,
CASE WHEN soitem.fcfromtype <> 'IFPKIT' THEN soitem.fpartno ELSE soitem.fcfromno END AS Item,
CASE WHEN soitem.fcfromtype <> 'IFPKIT' THEN soitem.fquantity ELSE soitem.fquantity / soitem.fquoteqty END AS Qty,
CASE WHEN soitem.fcfromtype <> 'IFPKIT'
THEN CAST(soitem.fdesc as CHAR(35))
ELSE 'Store Set (Phantom)' END as Descr,
somast.fordername,
soitem.fcfromno,
soitem.fcfromtype,
MIN(soitem.finumber) OVER (PARTITION BY soitem.fsono, soitem.fcfromno) AS min_finumber,
Attention = Case
when (CONVERT(VARCHAR(MAX), soship.fmstreet)) like 'ATTN%'
Then Left(CONVERT(VARCHAR(MAX), soship.fmstreet),CHARINDEX(CHAR(10),CONVERT(VARCHAR(MAX), soship.fmstreet)))
when (CONVERT(VARCHAR(MAX), soship.fmstreet)) Not like 'ATTN%'
Then REPLICATE((CASE WHEN [id] = 2 THEN s.val ELSE NULL END),1)
Else null
END,
Address1 = CASE
when (CONVERT(VARCHAR(MAX), soship.fmstreet)) Not like 'ATTN%'
Then REPLICATE((CASE WHEN [id] = 1 THEN s.val ELSE NULL END),1)
WHEN [id] = 2 THEN s.val
End
,
Address2 = CASE WHEN [id] = 3 THEN s.val ELSE NULL END
from soitem INNER JOIN
somast ON soitem.fsono = somast.fsono
INNER JOIN
soship ON somast.fsono = soship.fcsono AND soship.fcenumber = ''
Cross apply [dbo].[split3] (REPLACE(CONVERT(VARCHAR(MAX), soship.fmstreet), '&', 'and'),char(13) + char(10)) as S
WHERE
(somast.fstatus <> 'Cancelled') AND (somast.fsocoord = 'IFP' OR
somast.fsocoord = '711') and somast.forderdate >'07-01-2018'
) as A
group by
a.fsono,
a.fcustno,
a.ShipCode,
a.Item,
a.Qty,
a.Descr,
a.fordername,
a.fcusrchr2,
a.fcusrchr3,
a.fcusrchr1,
a.fcfromtype,
a.min_finumber
order by a.fsono, a.min_finumber;