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 2012 Forums
 Transact-SQL (2012)
 DIfficult Querry Need help.

Author  Topic 

yguyon
Starting Member

11 Posts

Posted - 2015-02-05 : 12:15:14
Table F4801

WADOCO / WARCTO/ WAPARS / WASRST /WARORN
2 / JT / / 5 / 032
4 / JT / 05 / 10 / 032
5 / JT / 03353 / 10 / 032
3353 / JT / 04 / 10 / 032
2323 / JT / 02323 / 10 / 032


From the table I want to return a set of record 2, 4, 5, 3353, 2323 from the column WADOCO
2 is the parents and 4,5,3353,2323 is the child


The query should meet the following requirement to return WADOCO = 2

WACTO = 'JT'
WASRST = '05'
and WAPARS = ' '

This is a simple select statement.

Select WADOCO
from table XXX
where WACTO = 'JT'
and WASRST = '04'
and WAPARS = ' '

The difficult part is to return the child of 2 such as 4, 5, 3353, 2323
And the child should meet the following requirement

WASRST >= '09'
WASRST <= '10'
and the value of WAPARS in the child exist in the column of WADOCO


How do I try to combine two querry in one. I tried the following querry but no luck.


with ctweg as (
select WARORN
from F4801
where WAPARS IN (SELECT WADOCO FROM F4801)
AND WASRST >= '02'
AND WASRST <= '05'
)

select *
FROM F4801
WHERE WARCTO = 'JT'
AND WAPARS = ' '
AND WASRST >= '09'
AND WASRST <= '10'
AND WARORN = ( SELECT * FROM ctweg)

Bustaz Kool
Master Smack Fu Yak Hacker

1834 Posts

Posted - 2015-02-05 : 18:46:54
How do you know which record is he child of another? How do you know which record is a root parent?



Those who will not reason, are bigots, those who cannot, are fools, and those who dare not, are slaves. -Lord Byron, poet (1788-1824)
Go to Top of Page

yguyon
Starting Member

11 Posts

Posted - 2015-02-06 : 10:42:58
quote:
Originally posted by Bustaz Kool

How do you know which record is he child of another? How do you know which record is a root parent?



Those who will not reason, are bigots, those who cannot, are fools, and those who dare not, are slaves. -Lord Byron, poet (1788-1824)




How do I know how to tell wich one is the parent and wich one is the child.

The parent such as 2(WADOCO) as a value of WAPARS = ' '

And the child its value in the WAPARS columns exist in the WADOCO column.

As an example the value of 4 will have a value in WAPARS of 86 that exist in the WARORN column of 2


Here is a better explanation

WADOCO - WAPARS - WARORN
2 - ' ' - 86
33 - 89 - 98
4 - 86 - 78
Go to Top of Page

Bustaz Kool
Master Smack Fu Yak Hacker

1834 Posts

Posted - 2015-02-06 : 16:23:32
All of the WARORN values are "032" for the entire table. Here is the data you presented
WADOCO /WARCTO /WAPARS /WASRST /WARORN
2 / JT / "" / 5 / 032
4 / JT / 05 / 10 / 032
5 / JT / 03353 / 10 / 032
3353 / JT / 04 / 10 / 032
2323 / JT / 02323 / 10 / 032
I don't see half of the values you mention (89, 86, 98, 78, etc.)



Those who will not reason, are bigots, those who cannot, are fools, and those who dare not, are slaves. -Lord Byron, poet (1788-1824)
Go to Top of Page
   

- Advertisement -