0

I am trying to load data into SQL server table. here is my code;

from OPENROWSET('SQLOLEDB', 'Server=(local);Trusted_Connection=yes;',
        'EXEC [dbo].[sp_model1]   @model   = ''predict1''',
         'EXEC [dbo].[sp_model2]   @model1    =  ''predict2''',
               @q =''SELECT *   FROM [tcs].[dbo].[fact_FY2019_FY2021]
                                where
                                [date] >= ''''2021-02-03 00:00:00''''
                              and  id = 11 order by key;'''
)as a
GO

Every time i run my insert statement along with above code, i get the following error

OLE DB provider "SQLNCLI11" for linked server "(null)" returned message "Deferred prepare could not be completed.".
Incorrect syntax near the keyword 'EXEC'.

Not sure why am i getting this error.

Any help would be appreciated.

9
  • 1
    check your quotes 'EXEC ............... ''predict1''', 'EXEC .......... ''predict2''', dbfiddle.uk/… Commented Jun 28, 2022 at 6:38
  • 1
    i did. tried all possible ways to figure that out. dont know still getting that error Commented Jun 28, 2022 at 6:39
  • 1
    checked and updated my ques with missing quotes. still the same Commented Jun 28, 2022 at 6:50
  • 2
    What are you trying to achieve here ? You are executing 2 stored procedure here. OPENROWSET will not be able to return multiple result set Commented Jun 28, 2022 at 7:01
  • 1
    Please do check the documentation for the correct syntax and usage of the function Commented Jun 28, 2022 at 7:10

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.