Database Management
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Clickatell
Go Back   Dev Shed ForumsDatabasesDatabase Management

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 Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old June 24th, 2003, 01:41 PM
narsibvl narsibvl is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 9 narsibvl User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
SQL Query

Just a beginner with SQL and Stored procedures
Here is the scenario(A simplified version of it)

I have a table that has the following fields

Order_No
Due_Date

and say the table name is "Past_Due"

Now i need to write a stored procedure to return three fields in a cursor

The three fields are
1. No of orders that are 10 days past due(Due date + 10 < system date)

2. No of orders that are 20 days past due

3. No of orders that are 30 days past due.

Can any point out the most efficient way to write a sql for this in a stored procedure.

TIA
Narsi

Reply With Quote
  #2  
Old June 24th, 2003, 06:16 PM
ecit12's Avatar
ecit12 ecit12 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 411 ecit12 User rank is Corporal (100 - 500 Reputation Level)ecit12 User rank is Corporal (100 - 500 Reputation Level)ecit12 User rank is Corporal (100 - 500 Reputation Level)ecit12 User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 2 Days 12 h 42 m 14 sec
Reputation Power: 6
do you mean u want the Order number of the orders or the count of the orders that are 10 days past the due date...

when u mean 10 days past the due date.. do u mean if an order is less than 10 days past the due date.. or just when it reaches the number 10..

If u stored the DueDate field as type Date u should be able to do this

DueDate-Date() which returns the how much the order os overdue by

I can help u better if u can answer the above 2 questions..

Reply With Quote
  #3  
Old June 25th, 2003, 08:40 AM
narsibvl narsibvl is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 9 narsibvl User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally posted by ecit12
do you mean u want the Order number of the orders or the count of the orders that are 10 days past the due date...

when u mean 10 days past the due date.. do u mean if an order is less than 10 days past the due date.. or just when it reaches the number 10..

If u stored the DueDate field as type Date u should be able to do this

DueDate-Date() which returns the how much the order os overdue by

I can help u better if u can answer the above 2 questions..


Here are couple of things I guess i failed to mention.

I need a single select query for doing this.

The Order_No field is not unique in the file and i need a count of the unique order, nos.

When i say 10 days past due i mean order that have been past due for the last 10 days and not 20 days. i. e. due date + 10 < sysdate and due date + 20 > sysdate

Reply With Quote
  #4  
Old June 26th, 2003, 02:27 AM
ecit12's Avatar
ecit12 ecit12 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 411 ecit12 User rank is Corporal (100 - 500 Reputation Level)ecit12 User rank is Corporal (100 - 500 Reputation Level)ecit12 User rank is Corporal (100 - 500 Reputation Level)ecit12 User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 2 Days 12 h 42 m 14 sec
Reputation Power: 6
ok.. here we go..

the following query will return all the orders that are between 10 to 19 days beyond the due date..
when u minus two dates, the value returned is the number of days...

select Order_No,
sum(
iif(dueDate-Date()>9 AND dueDate-Date()<20, 1,0)
)
From yourTable
Group By Order_No;

the above query should return all orders that are 10 to 19 days overdue..

somethings to keep in mind.. iif() is not part of sql.. its part of VB, its an if else statement.. and should work in Access and MS SQL server
the way it works is.. iif(condition,ture,false)
e.g. iif(heightOver6Feet, tallPerson, normalPerson)

hopefully that helps..

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesDatabase Management > SQL Query


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 4 hosted by Hostway