Menno
Menno

Reputation: 55

Run function with select statement

I have a tabe valued function called "GetLogInfosMsg" which I want to run provided with some Parameters from a specific table. The code below does not work; I get the message "Only one expression can be specified in the select list when the sub-query is not introduced with EXISTS.". Can somebody help me? Thanks.

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

Upvotes: 1

Views: 93

Answers (2)

t-clausen.dk
t-clausen.dk

Reputation: 44326

If you are using mssql 2005+ consider using this:

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

Upvotes: 0

sangram parmar
sangram parmar

Reputation: 8726

try this

you have to pass parameter in separate not in table format

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

Upvotes: 1

Related Questions