1

For some reason, I had to execute stored procedure from a function and since it is not possible and I tried as explained at Stackoverflow :: Execute Stored Procedure from a Function

Instead osql, I tried sqlcmd. It worked but I get multiple blank rows, rows with ------ and rows with NULL value.

This function can not be changed to stored procedure.

Is there any way to suppress these messages and unwanted rows ?

Or is there any alternative for executing stored procedure inside functions ?

enter image description here

Sql:

master..xp_cmdshell 'sqlcmd -COM252\INSTANCE2008 -E -q 
       "SET NOCOUNT ON;
        exec MyDatabaseName..storedProcName ''param1'', ''param2'' "'

I even tried pushing on temporary tables but unfortunately again, temporary tables can not be accessed on function.

Community
  • 1
  • 1
hsuk
  • 6,770
  • 13
  • 50
  • 80

1 Answers1

0

Haven't tried it, but how about this?

DECLARE @dummy TABLE(f1 varchar(max));

INSERT @dummy (f1)
EXEC master..xp_cmdshell 'sqlcmd -COM252\INSTANCE2008 -E -q 
       "SET NOCOUNT ON;
        exec MyDatabaseName..storedProcName ''param1'', ''param2'' "'
Kevin Suchlicki
  • 3,096
  • 2
  • 15
  • 17
  • In fact I am going to execute this on SQL function. This error `Invalid use of a side-effecting operator 'INSERT EXEC' within a function.` will be fired if I attempt your solution. – hsuk Feb 05 '14 at 23:13