При создании функции
IF NOT OBJECT_ID('[dbo].[atc_fn_GetReportOnAlloys]') IS NULL BEGIN
DROP FUNCTION [dbo].atc_fn_GetReportOnAlloys END
GO
CREATE FUNCTION [dbo].atc_fn_GetReportOnAlloys(@usrGradesId nvarchar(MAX), @locale nvarchar(MAX)) RETURNS TABLE AS RETURN
(SELECT UsrGradesId = ug.Id,
uts.Id AS [UsrTechSpecId],
IIF(@locale = 'en', uts.UsrName, '') AS [UsrTechSpecName],
(SELECT ucc.UsrGradeId AS [UsrChemicalCompo.Id],
ue.[Name] AS [UsrChemicalCompo.Hader],
ucc.UsrMax AS [UsrChemicalCompo.Max],
ucc.UsrMin AS [UsrChemicalCompo.Min]
FROM UsrChemicalCompos ucc
JOIN UsrElements ue ON ue.Id = ucc.UsrElementId
WHERE ucc.UsrGradeId = ug.Id
FOR JSON PATH) AS [UsrChemicalCompos]
FROM UsrGrades ug
RIGHT OUTER JOIN UsrTechSpec uts ON uts.Id = ug.UsrTechSpecId
LEFT JOIN SysUsrTechSpecFolderLcz sutsl ON sutsl.RecordId = uts.Id
WHERE convert(nvarchar(64), ug.Id) IN(
(SELECT Item
FROM dbo.atc_fn_SplitString(@usrGradesId, ';')))
FOR JSON PATH,
ROOT('UsrGrades'));
Ошибка на строчке
FOR JSON PATH, ROOT('UsrGrades'));
(если ее убираю то функция создается)
Не удалось выполнить инструкцию CREATE FUNCTION, так как не указано имя столбца 1.
Если этот запрос сделать в не функции то все нормально.