Click here to Skip to main content
16,020,188 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am currently writing a sql script to return data if a user searches by certain criteria
*Supplier
*Approver
*Capturer

I have 2 tables which are joined
1 users/supplier

the users belong to a group which would determine if they are approver or capturer
Groupid Description
1 approver
2- Capturer

now the issue i am having is when trying filter data

so if the user wants to search for a supplier and an approver but limit the capturer i have a slight issue.my script is in the what have i tried below.

How could i improve my script

What I have tried:

SQL
Select Supplier.id,Supplier.SupplierDescription,User.Username Approver,''capturer
from supplier,user
where user.groupid = 1 --Approver
Union all 
Select Supplier.id,Supplier.SupplierDescription,''Approver,user.Username Capturer
from supplier,user
where user.groupid = 2 --Capturer

Now if the user decided they would like to search for all suppliers and 1 approver and all capturers

this is the script i currently have
SQL
Select Supplier.id,Supplier.SupplierDescription,User.Username Approver,''capturer
from supplier,user
where user.groupid = 1 --Approver
and user.Userkey = 150
Union all 
Select Supplier.id,Supplier.SupplierDescription,''Approver,user.Username Capturer
from supplier,user
where user.groupid = 2 --Capturer
and supplier.id in(Select Supplier.id
from supplier,user
where user.groupid = 1 --Approver
and user.Userkey = 150)
Posted
Updated 23-Jun-16 1:15am
v3
Comments
CHill60 23-Jun-16 7:33am    
I don't think you need to use UNION but your requirements are not at all clear.
What is the link between table Supplier and table user?
Can a user be both an Approver and a Capturer?
Is UserKey 150 the "current user" running the query?

1 solution

Create a view which will be more faster.
 
Share this answer
 
Comments
CHill60 23-Jun-16 7:33am    
Perhaps giving the OP a clue as to what that view might look like would be more helpful.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900