SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Iron Speed
Go Back   ASP Free ForumsDatabaseSQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old April 29th, 2008, 01:50 AM
Coenen8 Coenen8 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 6 Coenen8 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 33 m 9 sec
Reputation Power: 0
Question Query - General - Query with temperorary tables?

Hello,

ik have the following tables

Order
-----
Orderno
customer
note_id

orderline
------------
ordern
lineno

note_id
note_text

chargeline
------------
orderno
chargelineno
note_id

note
--------
note_id
note_text

An order can have more than one orderline and more than one chargeorderline. You can store a text at orderlevel, orderlinelevel and at chargelinelevel (is not mandatory). I want to create a report which can show all these 3 text per order (and only shows an order when a text is available). I tried it with the following query which put the text for the orderlines and the text for the chargeorderlines in a temperorary table first. But this doesn't seem to work. Does anyone has an idea? Thanks!

select c.ordernr,
c.klantnr,
d.notitie_text,
l.regelnr,
l.notitie_text,
nvl(s2.sequence_no,'') Toeslagregelnr,
nvl(s2.note_text,'') Toeslagregeltekst
from order c,
orderregel l,
notitie d,

(select c.ordernr, l.regelnr, l.notitietekst
from order c, orderregel l
where c.ordernr = l.ordernr
and l.notitie_text is not NULL) s1

(select c.ordernr, ch.toeslagregelnr, d.notitie_text
from order c, toeslagregel ch, notitie_text d
where c.ordernr = ch.ordernr
and ch.notitie_id = d.notitie_id) s2

where c.ordernr = sl.ordernr(+)
and c.ordernr = s2.ordernr (+)
and c.notitie_id = d.notitie_id

Reply With Quote
  #2  
Old April 29th, 2008, 07:36 AM
gzaban gzaban is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2005
Posts: 19 gzaban User rank is Sergeant (500 - 2000 Reputation Level)gzaban User rank is Sergeant (500 - 2000 Reputation Level)gzaban User rank is Sergeant (500 - 2000 Reputation Level)gzaban User rank is Sergeant (500 - 2000 Reputation Level)gzaban User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 4 h 3 m 18 sec
Reputation Power: 0
Quote:
Originally Posted by Coenen8
Hello,

ik have the following tables

Order
-----
Orderno
customer
note_id

orderline
------------
ordern
lineno

note_id
note_text

chargeline
------------
orderno
chargelineno
note_id

note
--------
note_id
note_text

An order can have more than one orderline and more than one chargeorderline. You can store a text at orderlevel, orderlinelevel and at chargelinelevel (is not mandatory). I want to create a report which can show all these 3 text per order (and only shows an order when a text is available). I tried it with the following query which put the text for the orderlines and the text for the chargeorderlines in a temperorary table first. But this doesn't seem to work. Does anyone has an idea? Thanks!

select c.ordernr,
c.klantnr,
d.notitie_text,
l.regelnr,
l.notitie_text,
nvl(s2.sequence_no,'') Toeslagregelnr,
nvl(s2.note_text,'') Toeslagregeltekst
from order c,
orderregel l,
notitie d,

(select c.ordernr, l.regelnr, l.notitietekst
from order c, orderregel l
where c.ordernr = l.ordernr
and l.notitie_text is not NULL) s1

(select c.ordernr, ch.toeslagregelnr, d.notitie_text
from order c, toeslagregel ch, notitie_text d
where c.ordernr = ch.ordernr
and ch.notitie_id = d.notitie_id) s2

where c.ordernr = sl.ordernr(+)
and c.ordernr = s2.ordernr (+)
and c.notitie_id = d.notitie_id


Try this. I started by simplifying the query - and if I understand the information you provided correctly - this might do what you want (i.e. only display rows where at least one test is available)

Code:
select c.ordernr, 
c.klantnr,
d.notitie_text,
l.regelnr,
l.notitie_text,
nvl(ch.toeslagregelnr,'') Toeslagregelnr,
nvl(d2.notietie_text,'') Toeslagregeltekst
from 
order c
left join
notitie_text d on c.notitie_id = d.notitie_id
left join
orderregel l on c.ordernr = l.ordernr
left join
toeslagregel ch on c.ordernr = ch.ordernr
left join
notitie_text d2 on ch.notitie_id = d.notitie_id
where l.notitie_text is not null or d.notitie_text is not null
or d2.notitie_text is not null

Reply With Quote
  #3  
Old April 29th, 2008, 08:52 AM
Coenen8 Coenen8 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 6 Coenen8 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 33 m 9 sec
Reputation Power: 0
--

Reply With Quote
  #4  
Old April 29th, 2008, 08:58 AM
Coenen8 Coenen8 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 6 Coenen8 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 33 m 9 sec
Reputation Power: 0
thanks for your reply (and sorry for my incomplete translation). It is still not working the way i would like. I found out that the note_id in orderline also refers to the note_id in table note (and not has a value in l.notitie_text). So I rebuild your query like this:

select c.ordernr,
c.klantnr,
d.notitie_text,
nvl(ch.sequencenr,''),
nvl(d2.notitie_text,''),
nvl(l.linenr,''),
nvl(d3.notitie_text,'')
from
order c
left join
notitie_text d on c.notitie_id = d.notitie_id
left join
orderregel l on c.ordernr = l.ordernr
left join
toeslagregel ch on c.ordernr = ch.ordernr
left join
notitie_text d2 on ch.notitie_id = d.notitie_id
left join
notitie_text d3 on l.notitie_id = d.notitie_id
where d.notitie_text is not null or d2.notitie_text is not null
or d3.notitie_text is not null

But now I don't get my orders with only a orderline_text or a chargeline_text. I only get the orders with a ordertext. I guess that has something to do with the first join. But i'm not sure because an order always has a notitie_id. Do you have any idea?

Reply With Quote
  #5  
Old May 1st, 2008, 04:59 AM
gzaban gzaban is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2005
Posts: 19 gzaban User rank is Sergeant (500 - 2000 Reputation Level)gzaban User rank is Sergeant (500 - 2000 Reputation Level)gzaban User rank is Sergeant (500 - 2000 Reputation Level)gzaban User rank is Sergeant (500 - 2000 Reputation Level)gzaban User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 4 h 3 m 18 sec
Reputation Power: 0
Quote:
Originally Posted by Coenen8
thanks for your reply (and sorry for my incomplete translation). It is still not working the way i would like. I found out that the note_id in orderline also refers to the note_id in table note (and not has a value in l.notitie_text). So I rebuild your query like this:

select c.ordernr,
c.klantnr,
d.notitie_text,
nvl(ch.sequencenr,''),
nvl(d2.notitie_text,''),
nvl(l.linenr,''),
nvl(d3.notitie_text,'')
from
order c
left join
notitie_text d on c.notitie_id = d.notitie_id
left join
orderregel l on c.ordernr = l.ordernr
left join
toeslagregel ch on c.ordernr = ch.ordernr
left join
notitie_text d2 on ch.notitie_id = d.notitie_id
left join
notitie_text d3 on l.notitie_id = d.notitie_id
where d.notitie_text is not null or d2.notitie_text is not null
or d3.notitie_text is not null

But now I don't get my orders with only a orderline_text or a chargeline_text. I only get the orders with a ordertext. I guess that has something to do with the first join. But i'm not sure because an order always has a notitie_id. Do you have any idea?


You made a slight mistake when joining d2 and d3. I've bolded my changes for you. This should work.

Code:
select c.ordernr, 
c.klantnr,
d.notitie_text,
nvl(ch.sequencenr,''),
nvl(d2.notitie_text,''),
nvl(l.linenr,''),
nvl(d3.notitie_text,'') 
from 
order c
left join
notitie_text d on c.notitie_id = d.notitie_id 
left join
orderregel l on c.ordernr = l.ordernr
left join
toeslagregel ch on c.ordernr = ch.ordernr
left join
notitie_text d2 on ch.notitie_id = d2.notitie_id
left join
notitie_text d3 on l.notitie_id = d3.notitie_id
where d.notitie_text is not null or d2.notitie_text is not null
or d3.notitie_text is not null
Comments on this post
micky agrees!

Reply With Quote
  #6  
Old May 2nd, 2008, 01:58 AM
Coenen8 Coenen8 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 6 Coenen8 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 33 m 9 sec
Reputation Power: 0
Talking

Thanks man! That's a good start of my day. It works fine now!!

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseSQL Development > Query - General - Query with temperorary tables?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway