文件访问的一个存储过程,怎么写比较好?
表A
UserID Grup
1 2
1 4
2 3
表B
FileNo Priv
1001 1,2,5
1002 2,3
1003 3
如果传入参数UserID,要查询出UserID能访问的表B的记录,怎么写比较好
如果参数为1 返回
1001
1002
如果参数为2 返回
1002
1003
[解决办法]
select b.filenofrom a,bwhere charindex(a.grup,Priv)>0 and a.UserID=1
[解决办法]
declare @表A table(userid int,grup varchar(10))insert into @表A select 1,2insert into @表A select 1,4insert into @表A select 2,3declare @表B table(FileNo varchar(10),Priv varchar(10))insert into @表B select '1001','1,2,5'insert into @表B select '1002','2,3'insert into @表B select '1003','3'declare @userid intset @userid=1select fileno from @表A a,@表B bwhere charindex(a.grup,b.priv)>0and a.userid=@userid