2013-10-08 35 views
2

我有一個存儲過程,它從[inj-pois]中選擇/連接約25個表,並從另一個數據庫[nhisdb]中選擇一個字段。我遇到問題,授予許可讓用戶能夠訪問輔助數據庫[nhisdb]。他們已被授予[inj_pos]存儲過程的EXECUTE權限,並且他們已被授予[nhis]。[dbo]。[UserProfile]表的SELECT權限。但是,當用戶運行報告時,它會引發錯誤,說明未授予[UserProfile}表的授權。有什麼建議?以下是我的存儲過程。存儲過程從另一個數據庫中選擇的權限問題

select datarecords.ControlNumber,datarecords.fpx,datarecords.ipepno,datarecords.age, datarecords.sex,datarecords.icaus,datarecords.iphow,datarecords.ijbody1,datarecords.ijbody2,datarecords.ijbody3,datarecords.ijbody4,datarecords.ijbodyos,datarecords.ijtype1a,datarecords.ijtype1b,datarecords.ijtype2a,datarecords.ijtype2b,ijtype3a,datarecords.ijtype3b,datarecords.ijtype4a,datarecords.ijtype4b,datarecords.ijtyp1os,datarecords.ijtyp2os,datarecords.ijtyp3os,datarecords.ijtyp4os,datarecords.imtraf,datarecords.imvwho,datarecords.imvtyp,datarecords.isbelt,datarecords.ihelmt,datarecords.ifall1,datarecords.ifall2,datarecords.ifallwhy,datarecords.ppois,datarecords.ppoisos,datarecords.ipwhat1,datarecords.ipwhat2,datarecords.ipwhatot,datarecords.ipwher1,datarecords.ipwher2,adjudicd1 as icd1,adjudicd2 as icd2,adjudicd3 as icd3,adjudicd4 as ICD4,adjudicd5 as icd5,adjudicd6 as icd6,adjudicd7 as icd7,adjudicd8 as icd8,adjudECode1 as ECode1,AdjudEcode2 as Ecode2,adjudECode3 as ECode3,@booltrue as rekey,@booltrue as adjudicated 
,ipepnotext,sextext,icaustext, DataRecords.BatchID, DataRecords.UserID, Batch.[Quarter], nhisdb.dbo.UserProfile.UserName, 
datarecords.iphow as iphowtext, 
ijbody1.ijbodytext as ijbody1text,ijbody2.ijbodytext as ijbody2text, 
ijbody3.ijbodytext as ijbody3text,ijbody4.ijbodytext as ijbody4text, 
isnull(ijbodyos.ijbodyostext,datarecords.ijbodyos) as ijbodyostext, 
ijtype1a.ijtypetext as ijtype1Atext,ijtype1b.ijtypetext as ijtype1Btext,ijtype2a.ijtypetext as ijtype2Atext,ijtype2b.ijtypetext as ijtype2btext 
,ijtype3a.ijtypetext as ijtype3Atext,ijtype3b.ijtypetext as ijtype3btext,ijtype4a.ijtypetext as ijtype4Atext,ijtype4b.ijtypetext as ijtype4btext, 
isnull(ijtyp1os.ijtypeostext,datarecords.ijtyp1os) as ijtyp1ostext,isnull(ijtyp2os.ijtypeostext,datarecords.ijtyp2os) as ijtyp2ostext, 
isnull(ijtyp3os.ijtypeostext,datarecords.ijtyp3os) as ijtyp3ostext,isnull(ijtyp4os.ijtypeostext,datarecords.ijtyp4os) as ijtyp4ostext, 
imtraf.imtraftext, 
imvwho, 
imvwhotext, 
imvtyp.imvtyptext, 
isbelt.isbelttext, 
ihelmt.ihelmttext, 
ifall1.ifall1text, 
ifall2.ifall2text, 
ifallwhy.ifallwhytext, 
ppois.ppoistext, 
isnull(ppois.ppoistext,datarecords.ppois) as ppoistext, 
ipwhat1.ipwhat1text, 
ipwhat2.ipwhat2text, 
isnull(ipwhatot.ipwhatottext,datarecords.ipwhatot) as ipwhatottext, 
ipwher1.ipwher1Text, 
ipwher2,ipwher2text 
from datarecords 
full join ipepno on ipepno.ipepnoid=datarecords.ipepno 
full join Sex on sex.sexid=datarecords.sex 
full join ICAUS on ICAUS.IcausID=dataRecords.icaus 
full join Ijbody IJBODY1 on Ijbody1.IJBodyid=datarecords.ijbody1 
full join IJbody IJBODY2 on IJBOdy2.IJBOdyID=datarecords.ijbody2 
full join ijbody ijbody3 on ijbody3.ijbodyid=datarecords.ijbody3 
full join ijbody ijbody4 on ijbody4.ijbodyid=datarecords.ijbody4 
full join ijbodyos on ijbodyos.ijbodyosid=datarecords.ijbodyos 
full join ijtype ijtype1a on ijtype1a.ijtypeid=datarecords.ijtype1a 
full join ijtype ijtype1b on ijtype1b.ijtypeid=datarecords.ijtype1b 
full join ijtype ijtype2a on ijtype2a.ijtypeid=datarecords.ijtype2a 
full join ijtype ijtype2b on ijtype2b.ijtypeid=datarecords.ijtype2b 
full join ijtype ijtype3a on ijtype3a.ijtypeid=datarecords.ijtype3a 
full join ijtype ijtype3b on ijtype3b.ijtypeid=datarecords.ijtype3b 
full join ijtype ijtype4a on ijtype4a.ijtypeid=datarecords.ijtype4a 
full join ijtype ijtype4b on ijtype4b.ijtypeid=datarecords.ijtype4b 
full join Ijtypeos ijtyp1os on ijtyp1os.ijtypeosid=datarecords.ijtyp1os 
full join Ijtypeos ijtyp2os on ijtyp2os.ijtypeosid=datarecords.ijtyp2os 
full join Ijtypeos ijtyp3os on ijtyp3os.ijtypeosid=datarecords.ijtyp3os 
full join Ijtypeos ijtyp4os on ijtyp4os.ijtypeosid=datarecords.ijtyp4os 
full join imtraf on imtraf.imtrafid=datarecords.imtraf 
full join imvwho on imvwho.imvwhoid=datarecords.imvwho 
full join imvtyp on imvtyp.imvtypid=datarecords.imvtyp 
full join isbelt on isbelt.isbeltid=datarecords.isbelt 
full join ihelmt on ihelmt.ihelmtid=datarecords.ihelmt 
full join ifall1 on ifall1.ifall1id=datarecords.ifall1 
full join ifall2 on ifall2.ifall2id=datarecords.ifall2 
full join ifallwhy on ifallwhy.ifallwhyid=datarecords.ifallwhy 
full join ppois on ppois.ppoisid=datarecords.ppois 
full join ppoisos on ppoisos.ppoisosid=datarecords.ppoisos 
full join ipwhat1 on ipwhat1.ipwhat1id=datarecords.ipwhat1 
full join ipwhat2 on ipwhat2.ipwhat2id=datarecords.ipwhat2 
full join ipwhatot on ipwhatot.ipwhatotid=datarecords.ipwhatot 
full join ipwher1 on ipwher1.ipwher1id=datarecords.ipwher1 
full join ipwher2 on ipwher2.ipwher2id=datarecords.ipwher2 
full join Batch on BatchID = datarecords.BatchID 
full join nhisdb.dbo.UserProfile on nhisdb.dbo.UserProfile.UserId = DataRecords.UserID 
where datarecords.batchid [email protected] and markedforrekey=1 
and (rekeyicd1<>adjudicd1 or rekeyicd2<>adjudicd2 or rekeyicd3<>adjudicd3 or rekeyicd4<>adjudicd4 or rekeyicd5<>adjudicd5 or rekeyicd6<>adjudicd6 or rekeyicd7<>adjudicd7 or rekeyicd8<>adjudicd8 or rekeyEcode1<>adjudEcode1 or rekeyECode2<>adjudEcode2 or rekeyECode3<>adjudECode3) 
union 
select datarecords.ControlNumber,datarecords.fpx,datarecords.ipepno,datarecords.age,datarecords.sex,datarecords.icaus,datarecords.iphow,datarecords.ijbody1,datarecords.ijbody2,datarecords.ijbody3,datarecords.ijbody4,datarecords.ijbodyos,datarecords.ijtype1a,datarecords.ijtype1b,datarecords.ijtype2a,datarecords.ijtype2b,ijtype3a,datarecords.ijtype3b,datarecords.ijtype4a,datarecords.ijtype4b,datarecords.ijtyp1os,datarecords.ijtyp2os,datarecords.ijtyp3os,datarecords.ijtyp4os,datarecords.imtraf,datarecords.imvwho,datarecords.imvtyp,datarecords.isbelt,datarecords.ihelmt,datarecords.ifall1,datarecords.ifall2,datarecords.ifallwhy,datarecords.ppois,datarecords.ppoisos,datarecords.ipwhat1,datarecords.ipwhat2,datarecords.ipwhatot,datarecords.ipwher1,datarecords.ipwher2,adjudicd1 as icd1,adjudicd2 as icd2,adjudicd3 as icd3,adjudicd4 as ICD4,adjudicd5 as icd5,adjudicd6 as icd6,adjudicd7 as icd7,adjudicd8 as icd8,adjudECode1 as ECode1,AdjudEcode2 as Ecode2,adjudECode3 as ECode3, @booltrue as rekey,@boolfalse as adjudicated 
,ipepnotext,sextext,icaustext,DataRecords.BatchID, DataRecords.UserID,Batch.[Quarter], nhisdb.dbo.UserProfile.UserName, 
isnull(iphow.iphowtext,datarecords.iphow) as iphowtext, 
ijbody1.ijbodytext as ijbody1text,ijbody2.ijbodytext as ijbody2text, 
ijbody3.ijbodytext as ijbody3text,ijbody4.ijbodytext as ijbody4text, 
isnull(ijbodyos.ijbodyostext,datarecords.ijbodyos) as ijbodyostext, 
ijtype1a.ijtypetext as ijtype1Atext,ijtype1b.ijtypetext as ijtype1Btext,ijtype2a.ijtypetext as ijtype2Atext,ijtype2b.ijtypetext as ijtype2btext 
,ijtype3a.ijtypetext as ijtype3Atext,ijtype3b.ijtypetext as ijtype3btext,ijtype4a.ijtypetext as ijtype4Atext,ijtype4b.ijtypetext as ijtype4btext, 
isnull(ijtyp1os.ijtypeostext,datarecords.ijtyp1os) as ijtyp1ostext,isnull(ijtyp2os.ijtypeostext,datarecords.ijtyp2os) as ijtyp2ostext, 
isnull(ijtyp3os.ijtypeostext,datarecords.ijtyp3os) as ijtyp3ostext,isnull(ijtyp4os.ijtypeostext,datarecords.ijtyp4os) as ijtyp4ostext, 
imtraf.imtraftext, 
imvwho, 
imvwhotext, 
imvtyp.imvtyptext, 
isbelt.isbelttext, 
ihelmt.ihelmttext, 
ifall1.ifall1text, 
ifall2.ifall2text, 
ifallwhy.ifallwhytext, 
ppois.ppoistext, 
isnull(ppois.ppoistext,datarecords.ppois) as ppoistext, 
ipwhat1.ipwhat1text, 
ipwhat2.ipwhat2text, 
isnull(ipwhatot.ipwhatottext,datarecords.ipwhatot) as ipwhatottext, 
ipwher1.ipwher1Text, 
ipwher2,ipwher2text 
from datarecords 
full join ipepno on ipepno.ipepnoid=datarecords.ipepno 
full join Sex on sex.sexid=datarecords.sex 
full join ICAUS on ICAUS.IcausID=dataRecords.icaus 
full join iphow on iphow.iphowid=datarecords.iphow 
full join Ijbody IJBODY1 on Ijbody1.IJBodyid=datarecords.ijbody1 
full join IJbody IJBODY2 on IJBOdy2.IJBOdyID=datarecords.ijbody2 
full join ijbody ijbody3 on ijbody3.ijbodyid=datarecords.ijbody3 
full join ijbody ijbody4 on ijbody4.ijbodyid=datarecords.ijbody4 
full join ijbodyos on ijbodyos.ijbodyosid=datarecords.ijbodyos 
full join ijtype ijtype1a on ijtype1a.ijtypeid=datarecords.ijtype1a 
full join ijtype ijtype1b on ijtype1b.ijtypeid=datarecords.ijtype1b 
full join ijtype ijtype2a on ijtype2a.ijtypeid=datarecords.ijtype2a 

full join ijtype ijtype2b on ijtype2b.ijtypeid=datarecords.ijtype2b 
full join ijtype ijtype3a on ijtype3a.ijtypeid=datarecords.ijtype3a 
full join ijtype ijtype3b on ijtype3b.ijtypeid=datarecords.ijtype3b 
full join ijtype ijtype4a on ijtype4a.ijtypeid=datarecords.ijtype4a 
full join ijtype ijtype4b on ijtype4b.ijtypeid=datarecords.ijtype4b 
full join Ijtypeos ijtyp1os on ijtyp1os.ijtypeosid=datarecords.ijtyp1os 
full join Ijtypeos ijtyp2os on ijtyp2os.ijtypeosid=datarecords.ijtyp2os 
full join Ijtypeos ijtyp3os on ijtyp3os.ijtypeosid=datarecords.ijtyp3os 
full join Ijtypeos ijtyp4os on ijtyp4os.ijtypeosid=datarecords.ijtyp4os 
full join imtraf on imtraf.imtrafid=datarecords.imtraf 
full join imvwho on imvwho.imvwhoid=datarecords.imvwho 
full join imvtyp on imvtyp.imvtypid=datarecords.imvtyp 
full join isbelt on isbelt.isbeltid=datarecords.isbelt 
full join ihelmt on ihelmt.ihelmtid=datarecords.ihelmt 
full join ifall1 on ifall1.ifall1id=datarecords.ifall1 
full join ifall2 on ifall2.ifall2id=datarecords.ifall2 
full join ifallwhy on ifallwhy.ifallwhyid=datarecords.ifallwhy 
full join ppois on ppois.ppoisid=datarecords.ppois 
full join ppoisos on ppoisos.ppoisosid=datarecords.ppoisos 
full join ipwhat1 on ipwhat1.ipwhat1id=datarecords.ipwhat1 
full join ipwhat2 on ipwhat2.ipwhat2id=datarecords.ipwhat2 
full join ipwhatot on ipwhatot.ipwhatotid=datarecords.ipwhatot 
full join ipwher1 on ipwher1.ipwher1id=datarecords.ipwher1 
full join ipwher2 on ipwher2.ipwher2id=datarecords.ipwher2 
full join Batch on BatchID = datarecords.BatchID 
full join nhisdb.dbo.UserProfile on nhisdb.dbo.UserProfile.UserId = DataRecords.UserID 
where datarecords.batchid [email protected] and markedforrekey=1 
union 

select datarecords.ControlNumber,datarecords.fpx,datarecords.ipepno,datarecords.age,datarecords.sex,datarecords.icaus,datarecords.iphow,datarecords.ijbody1,datarecords.ijbody2,datarecords.ijbody3,datarecords.ijbody4,datarecords.ijbodyos,datarecords.ijtype1a,datarecords.ijtype1b,datarecords.ijtype2a,datarecords.ijtype2b,ijtype3a,datarecords.ijtype3b,datarecords.ijtype4a,datarecords.ijtype4b,datarecords.ijtyp1os,datarecords.ijtyp2os,datarecords.ijtyp3os,datarecords.ijtyp4os,datarecords.imtraf,datarecords.imvwho,datarecords.imvtyp,datarecords.isbelt,datarecords.ihelmt,datarecords.ifall1,datarecords.ifall2,datarecords.ifallwhy,datarecords.ppois,datarecords.ppoisos,datarecords.ipwhat1,datarecords.ipwhat2,datarecords.ipwhatot,datarecords.ipwher1,datarecords.ipwher2,icd1,icd2,icd3,icd4 ,icd5,icd6,icd7,icd8,ECode1,Ecode2,ECode3,@boolfalse as rekey,@boolfalse as adjudicated 
,ipepnotext,sextext,icaustext,DataRecords.BatchID, DataRecords.UserID, Batch.[Quarter], nhisdb.dbo.UserProfile.UserName, 

isnull(iphow.iphowtext,datarecords.iphow) as iphowtext, 
ijbody1.ijbodytext as ijbody1text,ijbody2.ijbodytext as ijbody2text, 
ijbody3.ijbodytext as ijbody3text,ijbody4.ijbodytext as ijbody4text, 
isnull(ijbodyos.ijbodyostext,datarecords.ijbodyos) as ijbodyostext, 
ijtype1a.ijtypetext as ijtype1Atext,ijtype1b.ijtypetext as ijtype1Btext,ijtype2a.ijtypetext as ijtype2Atext,ijtype2b.ijtypetext as ijtype2btext 
,ijtype3a.ijtypetext as ijtype3Atext,ijtype3b.ijtypetext as ijtype3btext,ijtype4a.ijtypetext as ijtype4Atext,ijtype4b.ijtypetext as ijtype4btext, 
isnull(ijtyp1os.ijtypeostext,datarecords.ijtyp1os) as ijtyp1ostext,isnull(ijtyp2os.ijtypeostext,datarecords.ijtyp2os) as ijtyp2ostext, 
isnull(ijtyp3os.ijtypeostext,datarecords.ijtyp3os) as ijtyp3ostext,isnull(ijtyp4os.ijtypeostext,datarecords.ijtyp4os) as ijtyp4ostext, 
imtraf.imtraftext, 
imvwho, 
imvwhotext, 
imvtyp.imvtyptext, 
isbelt.isbelttext, 
ihelmt.ihelmttext, 
ifall1.ifall1text, 
ifall2.ifall2text, 
ifallwhy.ifallwhytext, 
ppois.ppoistext, 
isnull(ppois.ppoistext,datarecords.ppois) as ppoistext, 
ipwhat1.ipwhat1text, 
ipwhat2.ipwhat2text, 
isnull(ipwhatot.ipwhatottext,datarecords.ipwhatot) as ipwhatottext, 
ipwher1.ipwher1Text, 
ipwher2,ipwher2text 
from datarecords 
full join ipepno on ipepno.ipepnoid=datarecords.ipepno 
full join Sex on sex.sexid=datarecords.sex 
full join ICAUS on ICAUS.IcausID=dataRecords.icaus 
full join iphow on iphow.iphowid=datarecords.iphow 
full join Ijbody IJBODY1 on Ijbody1.IJBodyid=datarecords.ijbody1 
full join IJbody IJBODY2 on IJBOdy2.IJBOdyID=datarecords.ijbody2 
full join ijbody ijbody3 on ijbody3.ijbodyid=datarecords.ijbody3 
full join ijbody ijbody4 on ijbody4.ijbodyid=datarecords.ijbody4 
full join ijbodyos on ijbodyos.ijbodyosid=datarecords.ijbodyos 
full join ijtype ijtype1a on ijtype1a.ijtypeid=datarecords.ijtype1a 
full join ijtype ijtype1b on ijtype1b.ijtypeid=datarecords.ijtype1b 
full join ijtype ijtype2a on ijtype2a.ijtypeid=datarecords.ijtype2a 
full join ijtype ijtype2b on ijtype2b.ijtypeid=datarecords.ijtype2b 
full join ijtype ijtype3a on ijtype3a.ijtypeid=datarecords.ijtype3a 
full join ijtype ijtype3b on ijtype3b.ijtypeid=datarecords.ijtype3b 
full join ijtype ijtype4a on ijtype4a.ijtypeid=datarecords.ijtype4a 
full join ijtype ijtype4b on ijtype4b.ijtypeid=datarecords.ijtype4b 
full join Ijtypeos ijtyp1os on ijtyp1os.ijtypeosid=datarecords.ijtyp1os 
full join Ijtypeos ijtyp2os on ijtyp2os.ijtypeosid=datarecords.ijtyp2os 
full join Ijtypeos ijtyp3os on ijtyp3os.ijtypeosid=datarecords.ijtyp3os 
full join Ijtypeos ijtyp4os on ijtyp4os.ijtypeosid=datarecords.ijtyp4os 
full join imtraf on imtraf.imtrafid=datarecords.imtraf 
full join imvwho on imvwho.imvwhoid=datarecords.imvwho 
full join imvtyp on imvtyp.imvtypid=datarecords.imvtyp 
full join isbelt on isbelt.isbeltid=datarecords.isbelt 
full join ihelmt on ihelmt.ihelmtid=datarecords.ihelmt 
full join ifall1 on ifall1.ifall1id=datarecords.ifall1 
full join ifall2 on ifall2.ifall2id=datarecords.ifall2 
full join ifallwhy on ifallwhy.ifallwhyid=datarecords.ifallwhy 
full join ppois on ppois.ppoisid=datarecords.ppois 
full join ppoisos on ppoisos.ppoisosid=datarecords.ppoisos 
full join ipwhat1 on ipwhat1.ipwhat1id=datarecords.ipwhat1 
full join ipwhat2 on ipwhat2.ipwhat2id=datarecords.ipwhat2 
full join ipwhatot on ipwhatot.ipwhatotid=datarecords.ipwhatot 
full join ipwher1 on ipwher1.ipwher1id=datarecords.ipwher1 
full join ipwher2 on ipwher2.ipwher2id=datarecords.ipwher2 
full join Batch on BatchID = datarecords.BatchID 
full join nhisdb.dbo.UserProfile on nhisdb.dbo.UserProfile.UserId = DataRecords.UserID 
where markedforrekey=0 and batchid [email protected] 

回答

0

您還必須設置服務器以允許跨數據庫所有權鏈接或將數據庫標記爲可信。

相關問題