Hi PeaceOut,
Thanks for posting the store procedure(SP) sample. Based on my test, the error can be reproduced using the SP as below.
SELECT *
FROM OPENROWSET('SQLNCLI','server=SQL01;Trusted_Connection=yes',
'SET NOCOUNT ON;SET FMTONLY OFF;EXEC dbo.[usp_test] 1,1,1,1,1')
If the SP's body changes as below(one more column added), it would lead to another error "The metadata could not be determined...". This error is indeed related to your issue. Actually you're using linked server, this query would access your SQL Server
via SQL Native client driver, though you may run this statement in your Local SQL Server(SQL01 in your case). The IF..ELSE block should return the same number of columns with same column names in the same order, otherwise the driver could not accept a non-deterministic
result or a metadata inconsistent error when having different column names.
if
select cast(1 as varchar(10)) as t,2 as n
else
select cast(1 as varchar(10)) as p
So change the test SP's body as below to fix this kind of issue.
if 1=2
select cast(1 as varchar(10)) as p
else
select cast(1 as varchar(10)) as p
>thank you...i am not using a linked server, just trying to execute a stored procedure without declaring the results table.
I don't know where you learned such a technology to avoid declaring the results table,
but it is obviously not a good practice. If what you expect is the SP's result, you don't need to declare a result table, the SP would return a result table, if you'd like to store the result from the SP for further process, use an INSERT INTO
..EXEC SP syntax.
EXEC [usp_test] 1,1,1,1,1
DECLARE @T TABLE(num int)
INSERT INTO @T EXEC [usp_test] 1,1,1,1,1
SELECT * FROM @T
If you have any question, feel free to let me know.