Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select Query with Field Parameters??

Status
Not open for further replies.

lsmyth1717

Programmer
Mar 25, 2005
44
GB
I have to write a query which i've know idea how to write and was wondering
if someone can help me.

I've got an asp.net front end and i'm trying to run a query to select all
the users in table UserObjects which have a value '1'. This seems simple
enough however I have to offer them the options to choose the specific
field(s).

i.e I need to allow the user to return all the '1' for u_publications
or all the '1' for u_publication and u_policy.

Basically the checkbox list gives all three options and they can choose
which ever options they like. They can choose 1 option 2 options or all 3
options and I have to query the database accordingly

Below is a sample of the table. I hope everyone understands, lord know its
hard for me to explain.

Can someone please help me write this query. I would really appreciate any
help anyone can give me.

Table: UserObjects
u_publications u_policy u _press
0 1 1
1 0 0
0 0 1
0 1 1

 

Do you mean somthing like

Code:
create proc abc
@u_pub int = 0,
@u_Policy int = 0
@u_Press int = 0
as
if @u_pub = 1 and @u_policy = 1 and @u_PRess
  begin
     select * from userobjects where 
     u_publications = 1 and u_policy = 1 and u_press = 1
  end
else if @u_policy = 1 and @u_PRess
  begin
     select * from userobjects 
     where  u_policy = 1 and u_press = 1
  end
else if @u_pub = 1 and @u_policy =1 
  begin
     select * from userobjects 
     where u_publications = 1 and u_policy = 1  
 end

etc...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top