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
 problem on query

Author  Topic 

cwtriguns2002
Constraint Violating Yak Guru

272 Posts

Posted - 2007-03-03 : 03:36:31
table1 - pspersonaldata

dcno fullname religion
1 julie,angelina Born Again
2 Cage,Nicholas Roman Catholic
3 sample1 Adventist
4 sample2 Born Again
5 sample3 Adventist

table2 - hremployees
dcno Address telno
1 aaa bbb 111
2 aaa bbb 222
3 aaa bbb 333
4 aaa bbb 444
5 aaa bbb 555
6 aaa bbb 666
7 aaa bbb 777

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

I have problem on my query. It returns a data for a religion "Born Again" only.
How can I create a query that returns the value of Born Aagain and Adventist?
Thanks

-Ron-

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2007-03-03 : 04:51:08
your query is correct, your source data does not meet your criteria
do a manual check on the rows for religion adventist, see if the dcno is in both table1 and table2

HTH

--------------------
keeping it simple...
Go to Top of Page

cwtriguns2002
Constraint Violating Yak Guru

272 Posts

Posted - 2007-03-03 : 09:23:34
I don't think so. OK i'll check it in monday coz im not anymore in office.
Thanks
-Ron-
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2007-03-03 : 12:16:26
Well....since there is no col named empdcno, I'd say you are leaving something out.



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

cwtriguns2002
Constraint Violating Yak Guru

272 Posts

Posted - 2007-03-04 : 08:32:56
its empdcno, not dcno.
sorry table2 should be:

table2 - hremployees
empdcno Address telno
1 aaa 111
2 aaa 222
3 aaa 333
4 aaa 444
5 aaa 555
6 aaa 666
7 aaa 777
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-03-04 : 20:44:47
Your query looks fine. Is this what you want ?

declare @pspersonaldata table
(
dcno int,
fullname varchar(20),
religion varchar(20)
)
insert into @pspersonaldata
select 1, 'julie,angelina', 'Born Again' union all
select 2, 'Cage,Nicholas', 'Roman Catholic' union all
select 3, 'sample1', 'Adventist' union all
select 4, 'sample2', 'Born Again' union all
select 5, 'sample3', 'Adventist'

declare @hremployees table
(
empdcno int,
Address varchar(10),
telno varchar(10)
)
insert into @hremployees
select 1, 'aaa', 111 union all
select 2, 'aaa', 222 union all
select 3, 'aaa', 333 union all
select 4, 'aaa', 444 union all
select 5, 'aaa', 555 union all
select 6, 'aaa', 666 union all
select 7, 'aaa', 777

select P.fullname, P.religion, E.empdcno
from @pspersonaldata as P
inner join @hremployees as E on P.dcno = E.empdcno
where P.religion in ('Born Again', 'Adventist')
/*
fullname religion empdcno
-------------------- -------------------- -----------
julie,angelina Born Again 1
sample1 Adventist 3
sample2 Born Again 4
sample3 Adventist 5
*/



KH

Go to Top of Page
   

- Advertisement -