Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««12

Return result of dynamic query from function Expand / Collapse
Author
Message
Posted Thursday, October 25, 2007 8:48 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 5:56 PM
Points: 7,075, Visits: 15,325
rose_red1947 (10/24/2007)
Try with SET clause before @RESULT = Execute @SQLQuery


No....

Let's try this again. from BOL:


The types of statements that are valid in a function include:

DECLARE statements can be used to define data variables and cursors that are local to the function.

Assignments of values to objects local to the function, such as using SET to assign values to scalar and table local variables.

Cursor operations that reference local cursors that are declared, opened, closed, and deallocated in the function. FETCH statements that return data to the client are not allowed. Only FETCH statements that assign values to local variables using the INTO clause are allowed.

Control-of-flow statements except TRY...CATCH statements.

SELECT statements containing select lists with expressions that assign values to variables that are local to the function.

UPDATE, INSERT, and DELETE statements modifying table variables that are local to the function.

EXECUTE statements calling an extended stored procedure.

Notice the last line - you can only call Extended stored procs using exec. Dynamic SQL is not allowed.

And lest you ask: sp_executeSQL is not an extended stored proc, so it's not legal either.



----------------------------------------------------------------------------------
Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
Post #415000
« Prev Topic | Next Topic »

Add to briefcase ««12

Permissions Expand / Collapse