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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Difficult query

Author  Topic 

Ramnadh
Starting Member

23 Posts

Posted - 2004-06-10 : 01:50:46
Hi,
I have three tables with the Structures.

Table A : (EmpId , SystemId)
Table B : (SystemId)
Table C : (EmpId, SystemId, ImpSystemId, IsCompleted)

Table A is the Master table it is having all the rows.
Table B refers the Master table A which SystemId refers A.SystemId
Table C refers the Master table A which all the rows may not exists as in the Master Table.

The query is that we have to get the rows which the A.SystemId IN (B.SystemId)
and Have to ignore the rows with values in the Table C having ImpSystemId = 1 and IsCompleted = 1 and have to get the remaining rows.


Ramnadh

timmy
Master Smack Fu Yak Hacker

1242 Posts

Posted - 2004-06-10 : 02:18:19
Can you post some sample data and the required output?

It would make things much easier.

Go to Top of Page

Ramnadh
Starting Member

23 Posts

Posted - 2004-06-10 : 02:49:24
Table A :
EmpId SystemId
1 - 11
1 - 4
1 - 10
1 - 5
1 - 2
2 - 11
2 - 4
3 - 4
3 - 11

Table B :
SystemId
11
4

Table C :
EmpId - SystemId -ImpSystemId - IsCompleted
1 - 11 - 1 - 1
1 - 4 - 1 - 0
1 - 10 - 0 - 0
2 - 4 - 1 - 1
2 - 11 - 1 - 0
3 - 11 - 1 - 1


The result Set should be :

EmpId - SystemId
1 - 4
2 - 11
3 - 4

Means the systems in the Table B should contain compulsarily in the Table A and the EmpId & SystemId having ImpSystemId = 1 and Iscompleted = 1 should ignore.

Ramnadh
Go to Top of Page

JasonGoff
Posting Yak Master

158 Posts

Posted - 2004-06-10 : 09:42:43
You can ignore TableA and B if you want, as all the information you need is presented in TableC again, so...

SELECT EmpId, SystemId
FROM TableC
WHERE IsCompleted = 0 OR ImpSystemId = 0
Go to Top of Page
   

- Advertisement -