Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes JDBC and Relational Databases and the fly likes MS SQL Query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "MS SQL Query" Watch "MS SQL Query" New topic

MS SQL Query

Kalyani Nayak

Joined: Jan 01, 2006
Posts: 25
I want to invoke rows from a table in such a way that ,
suppose employeeAccess is my table i want to fetch all the records from employeeAccess table which
satisfy the following criteria as

if accessid = 1 then accessval = 'all'
if accessid = 2 then accessval = 'read'

I don't want to make the condition either or.

Suppose my table has some values like -




In the above case i only want to fetch the empid 2 . Neither 1 nor 3, as only
empid = 2 satisfy both condition that is for
empid = 2 when accessid = 1, accessval is 'all'
and when accessid = 2, accessval is 'read'
empid = 1 record is not expected, as in this case
when accessid = 1, accessval is 'all'
but when accessid = 2, accessval is something other than 'read'
empid = 3 record is also not expected, as in this case
when accessid = 2, accessval is 'read'
but when accessid = 1, accessval is something other than 'all'

Please, help me outof this.
Note: I can't change the table format.
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3740

You could probably solve this using an inner join of the table on itself with the empid field as the join condition such as:

Keep in mind there might be a shortcut I'm missing (its monday morning) and if the employee table is very big, joining on itself might not lead to the best performance.

[OCA 8 Book] [Blog]
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: MS SQL Query
jQuery in Action, 3rd edition