Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

How to cross two tables?

$
0
0

Greetings community,

This is totally beginner’s question, so accept my apology for bothering you with such a basic thing. At first I blamed Microsoft for giving us LINQ that was so easy to use and on the other side much slower intellisense in SSMS when typing queries, but it was my laziness to learn T-SQL properly at the end.

I have two tables that I have to cross. First is simple lookup table named LUItems that is consisted of these columns:

  • ItemID int – auto incremented key
  • Name  nvarchar(50)
  • ULoA  int (user’s level of authorization: 1 is lowest)

Second table is document details – for the simplicity of this question let’s say it’s consisted of only these columns:

  • DetailID int – auto incremented key
  • DocumentID int
  • ItemID int
  • DocDate  date

So I have some user logged in, who wants to see a document. I want to let him/her see only those document details that are at his/hers ULoA.

At first phase I create small lookup table from LUItems where I pull only those items whose ULoA is smaller or equal than particular user’s authority level. That table is attached on one binding source, so I could use item’s names in order to show them in data grid view that is dedicated to show document details.

At second phase I need to pull document’s details, but if I pull them all, data grid view would throw the exception if document contains some items that particular user is not supposed to see, because attached lookup in previously created binding source simply does not contain them.

What I need is stored procedure with entry parameters DocumentID and ULoA, which would result of only those document details for the particular document whose items’ ULoA are smaller or equal than entered.

Thanks for any help.


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>