2013-07-01 81 views
1

我有一個tabe的值函數叫做「GetLogInfosMsg」,我想運行一些特定的表。下面的代碼不起作用;我得到消息「當EXISTS沒有引入子查詢時,只能在選擇列表中指定一個表達式」。有人能幫助我嗎?謝謝。使用select語句運行函數

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

回答

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 
            )) ; 
+0

這工作, 非常感謝! – Menno

+0

所以請標記爲正確答案 –

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