Use Parameter In OPENROWSET Sql Server

后端 未结 1 1203
攒了一身酷
攒了一身酷 2021-01-24 09:25

I am creating an stored procedure in which I am calling an another stored procedure(This procedure is returned lot of columns and I want only one column value

相关标签:
1条回答
  • 2021-01-24 10:03

    You have to make your entire SELECT string dynamic:

     declare @AgencyID int=15,@PatientID int=3701
    DECLARE @SQLStr varchar(max)='
        SELECT a.PrimaryInsuredName 
            FROM OPENROWSET(''SQLNCLI'',  
            ''Server=ServerName;Database=DbName;Trusted_Connection=yes'',
            ''exec USP_Billing_GetPatientWithInsurence '+ CAST(@PatientID AS varchar(15)) +','+ CAST(@AgencyID AS varchar(15)) +''') AS a';
    EXECUTE(@SQLStr);
    
    0 讨论(0)
提交回复
热议问题