Declare @Result as varchar(max)='';
SELECT DISTINCT @Result = dbo.MaterialTypes.Title + ', '+ @Result
FROM dbo.TempId LEFT OUTER JOIN
dbo.ProductMaterials ON dbo.ProductMaterials.Product = dbo.TempId.Id LEFT OUTER JOIN
dbo.MaterialTypes ON dbo.ProductMaterials.MaterialType = dbo.MaterialTypes.Id LEFT OUTER JOIN
dbo.Products ON dbo.Products.Id = dbo.TempId.Id
WHERE (dbo.Products.IsCollection = 1)
SELECT DISTINCT dbo.TempId.Id AS MaterialCollection_id, @Result
FROM dbo.TempId LEFT OUTER JOIN
dbo.ProductMaterials ON dbo.ProductMaterials.Product = dbo.TempId.Id LEFT OUTER JOIN
dbo.MaterialTypes ON dbo.ProductMaterials.MaterialType = dbo.MaterialTypes.Id LEFT OUTER JOIN
dbo.Products ON dbo.Products.Id = dbo.TempId.Id
WHERE (dbo.Products.IsCollection = 1)
此查询有效,但我无法根据此查询创建视图。请帮忙!