SQL 2008中的函数 [英] Functions in SQL 2008

查看:127
本文介绍了SQL 2008中的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

CREATE FUNCTION GetClientName
(
    @JobId bigint
)
RETURNS VARCHAR(MAX)
AS
BEGIN
    DECLARE @ClientName AS VARCHAR(MAX)
    select @ClientName = c1.clientname FROM tbl_client c1
    INNER JOIN tbl_mechanicalbrief m ON m.clientid = c1.clientid
    WHERE mechanicalid = @JobId
    Union
    select @ClientName = c2.clientname FROM tbl_iteration i
    INNER JOIN tbl_client c2 ON i.clientid = c2.clientid
    WHERE iterationid = @JobId
    Union
    select @ClientName = c3.clientname FROM tbl_release r
    INNER JOIN tbl_client c3 ON r.clientid = c3.clientid
    WHERE releasingid = @JobId
    RETURN @ClientName
END



当我在上面的SQL语句中执行时,出现错误:



When I execute above SQL Statement it gives an error:

Select statements included within a function cannot return data to a client.





How can solve this problem??

推荐答案

在这里,这解释了为什么会这样以及如何解决它: SQL Server错误消息-消息444 [
Here you go, this explains why it is so and how it can be resolved: SQL Server Error Messages - Msg 444[^]


这篇关于SQL 2008中的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆