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
 General SQL Server Forums
 New to SQL Server Programming
 querying with 1, or 2, or multiple parameters

Author  Topic 

cwtriguns2002
Constraint Violating Yak Guru

272 Posts

Posted - 2007-03-04 : 20:30:58
Hi all. I have the problem on query.
This is my query.

select D.fullname, P.religion, E.empno from pspersonaldata as P
inner join hremployees as E on P.dcno = E.empdcno
inner join psdatacenter as D on D.dcno = E.empdcno
where P.religion in ('Born Again','Baptist', 'Catholic')

How could I make a query that returns a result for either "Born Again, Baptist, or Catholic". The parameter would depend on the input of the user depending on how many religion the user inputed.
If the user inputed Born Again and Baptist, the result is the employees that have a religion of Born Again and Baptist.
Thanks
-Ron-

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-03-04 : 20:45:48
a continuation of http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=79982 with new table to join ?


KH

Go to Top of Page

cwtriguns2002
Constraint Violating Yak Guru

272 Posts

Posted - 2007-03-04 : 22:32:57
Thanks KH for the time.
No. This is another problem. I want to make dynamic report in which the parameters are flexible. I mean, you can enter any number of parameters(Religion) in a fields. For example, in my windows application project, i have checkboxes, and the user will only check the religions he wants to show....be it Born Again, or Baptist, or catholic. Or the user can check all the religion. Is it possible to have a dynamic query for this?

Thanks.
-Ron-
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-03-04 : 22:52:41
[code]
select D.fullname, P.religion, E.empno
from pspersonaldata as P
inner join hremployees as E on P.dcno = E.empdcno
inner join psdatacenter as D on D.dcno = E.empdcno
inner join CSVTable(@religion) as R on P.religion = R.stringval -- Get CSVTable here
[/code]

also take a look here

KH

Go to Top of Page

cwtriguns2002
Constraint Violating Yak Guru

272 Posts

Posted - 2007-03-05 : 01:07:36
Thanks KH.
I have no idea of CSVTable. Im new newbie in SQL and queries.

DECLARE @religion varchar (100)
SET @religion = 'Born Again, Baptist'
select D.fullname, P.religion, E.empno
from pspersonaldata as P
inner join hremployees as E on P.dcno = E.empdcno
inner join psdatacenter as D on D.dcno = E.empdcno
inner join CSVTable(@religion) as R on P.religion = R.religion

I tried this but it doesnt work.
-Ron-
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-03-05 : 01:12:19
[code]
DECLARE @religion varchar (100)
SET @religion = 'Born Again, Baptist'

select D.fullname, P.religion, E.empno
from pspersonaldata as P
inner join hremployees as E on P.dcno = E.empdcno
inner join psdatacenter as D on D.dcno = E.empdcno
inner join CSVTable(@religion) as R on P.religion = R.stringval
[/code]

You have to get the CSVTable function from the link that i provided.


KH

Go to Top of Page

cwtriguns2002
Constraint Violating Yak Guru

272 Posts

Posted - 2007-03-05 : 02:24:30
Thanks KH. It works fine.
-Ron-
Go to Top of Page
   

- Advertisement -