Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
snufse
Constraint Violating Yak Guru
469 Posts |
Posted - 2008-06-16 : 09:25:20
|
| I need to write a sp (for my web app) that checks user authorization. Here is the scenario:User Authorization Table (AuthTable)UserID From Cost Center To Cost Center(UserId) (FromCC) (ToCC)User1 3000 3600User1 4800 5120User1 5200 5250User2 3000 3400User2 3760 3840Production Table (ProdTable) data:Job Number Cost Center Quantity(JobId) (JobCC) JobQty5100 2860 2505100 3120 5255100 4801 2625200 3001 1555200 5251 276I need to check the user security for each record that I read from the ProdTable against all entries in the AuthTable for the current user.When I read the ProdTable and User ID = User1 then selected records should be:5100/3120, 5100/4801, 5200/3001, When I read the ProdTable and UserID = User2, then the selected records should be:5200/3120I’m not sure how to construct my sql statement. Can somebody give me a hand? Thank you. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-06-16 : 10:25:24
|
| [code]SELECT LEFT(rl.resultlist,LEN(rl.resultlist)-1)FROM(SELECT JobId + '/' + JobCC + ',' AS [text()]FROM ProdTable ptINNER JOIN AuthTable atON pt.JobCC >=FromCC AND pt.JobCC <=ToCCWHERE at.UserId=@UserIDFOR XML PATH(''))rl(resultlist)[/code] |
 |
|
|
|
|
|