使用select语句运行函数

时间:2013-07-01 09:28:09

标签: tsql

我有一个名为“GetLogInfosMsg”的tabe值函数,我想运行该函数,并提供特定表中的一些参数。以下代码不起作用;我收到消息“当EXISTS没有引入子查询时,只能在选择列表中指定一个表达式。”有人能帮助我吗?感谢。

SELECT
    @pErrMsgID = [MsgID], 
    @pParams = [Params]
FROM 
    [dbo].[GetLogInfoMsg]((SELECT 
                               [FIELD1],
                               [FIELD2],
                               [FIELD3]
                           FROM [dbo].[TABLE1]
                           WHERE [TABLE1].[UUID] = @pUUID));

2 个答案:

答案 0 :(得分:1)

试试这个

你必须以单独的非表格格式传递参数

SELECT  @pErrMsgID = [MsgID] ,
        @pParams = [Params]
FROM    [dbo].[GetLogInfoMsg](( SELECT  [FIELD1]
                                FROM    [dbo].[TABLE1]
                                WHERE   [TABLE1].[UUID] = @pUUID
                              ), ( SELECT   [FIELD2]
                                   FROM     [dbo].[TABLE1]
                                   WHERE    [TABLE1].[UUID] = @pUUID
                                 ), ( SELECT    [FIELD3]
                                      FROM      [dbo].[TABLE1]
                                      WHERE     [TABLE1].[UUID] = @pUUID
                                    )) ;

答案 1 :(得分:0)

如果您使用的是mssql 2005+,请考虑使用:

SELECT
    @pErrMsgID = t2.[MsgID], 
    @pParams   = t2.[Params]
FROM [dbo].[TABLE1] t1
CROSS APPLY (SELECT [MsgID], [Params] 
FROM [dbo].[GetLogInfoMsg] (t1.FIELD1, t1.FIELD2, t1.FIELD3) t2
WHERE t1.[UUID] = @pUUID