虽然以下内容与子存储过程有关,但我认为该问题与在同一过程中传递值有关。
问题:
我想从我从存储过程调用的用户定义函数返回一个值
如果我对线路进行硬编码
SELECT @SiteImage = ImageName FROM TblImages WHERE SITEID = @SiteIDOriginal
要成为
SELECT @SiteImage = ImageName FROM TblImages WHERE SITEID = 'HARDCODED_SITE_ID'
然后它传回我想要的东西。
我相信我之前传递的是正确的变量,但需要一些指导,以便它“降低”值。
在'Parent'存储过程中,我请求:
dbo.GetPropertyImage(UPPER(@SITEID)) as SitePhoto
然后我按照以下步骤操作,并希望将值@SiteImage返回到此行,回传就像我提到的那样通过硬编码测试了它。
USE [cording]
GO
/****** Object: UserDefinedFunction [dbo].[GetPropertyImage] Script Date: 05/18/2015 09:17:14 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER FUNCTION [dbo].[GetPropertyImage]
(
-- Add the parameters for the function here
@SiteID varchar(100)
)
RETURNS varchar(100)
AS
BEGIN
-- Declare the return variable here
DECLARE @SiteImage varchar(100)
DECLARE @SiteIDOriginal varchar(100)
-- Add the T-SQL statements to compute the return value here
SELECT @SiteIDOriginal=PemcoShortCode FROM iBasePropertyDetails WHERE PemcoShortCode=@SiteID
SELECT @SiteImage = ImageName FROM TblImages WHERE SITEID = @SiteIDOriginal
--SiteID = @SiteIDOriginal
-- Return the result of the function
RETURN @SiteImage
END
答案 0 :(得分:0)
USE [Database]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER FUNCTION [dbo].[GetImage]
(
-- Add the parameters for the function here
@SiteID varchar(100)
)
RETURNS varchar(100)
AS
BEGIN
-- Declare the return variable here
DECLARE @SiteImage varchar(100)
DECLARE @SiteIDOriginal varchar(100)
-- Add the T-SQL statements to compute the return value here
SELECT [@SiteIDOriginal] = ID FROM iBasePropertyDetails WHERE PemcoShortCode=[@SiteID]
SELECT @SiteImage = ImageName FROM TblImages WHERE SITEID = @SiteIDOriginal
-- Return the result of the function
RETURN @SiteImage
END