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 =@Batchid 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  =@Batchid 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  =@Batchid
4

2 回答 2

1

使用EXECUTE AS OWNERhttp ://technet.microsoft.com/en-us/library/ms188354.aspx

只要创建存储过程的用户具有适当的访问权限,所有需要权限的用户只需被授予 EXECUTE 权限即可获得固有访问权限。

于 2013-10-08T20:02:54.413 回答
0

您还必须设置服务器以允许跨数据库所有权链接或将数据库标记为可信任。

于 2013-10-08T19:00:21.880 回答