如何在标量值函数中为列名使用变量?
CREATE FUNCTION [dbo].[GetValue]
(
@ID varchar(36),
@PreprtyName varchar(150)
)
RETURNS varchar(250)
AS
BEGIN
DECLARE @RetVal varchar(MAX)
DECLARE @SQL varchar(MAX)
SET @RetVal =''
SET @SQL = 'SET @RetVal = (Select '+ @PreprtyName + ' FROM TableMedia WHERE ID = '''+ @ID +')'''
exec @SQL
SET @RetVal = @RetVal
RETURN @RetVal
END
出现错误找不到“找不到存储过程”
这是我要避免的。
SELECT pr.ProductID, tManufacturerImage.Image, tMediaCenter.ManualFileName,tMediaCenter.BrochureFileName, tMediaCenter.AssemblyFileName
FROM tMediaCenter RIGHT OUTER JOIN
tProduct AS pr INNER JOIN
tmp_dmi AS dmi ON REPLACE(REPLACE(pr.SKU, 'ACS', ''), 'DMI', '') = RTRIM(LTRIM(dmi.pri_SKU)) ON tMediaCenter.ProductID = pr.ProductID LEFT OUTER JOIN
tManufacturer INNER JOIN
tManufacturerImage ON tManufacturer.ManufacturerID = tManufacturerImage.ManufacturerID ON pr.ManufacturerID = tManufacturer.ManufacturerID
WHERE (pr.ManufacturerID = 'f35fc01680-4938-4070-a367-38c31efb01f') AND (dmi.MAP IS NULL) AND (pr.ParentID <> '')
这对我不起作用。