MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesMS SQL 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 Dev Shed Forums Sponsor:
  #1  
Old August 13th, 2012, 07:37 AM
maluktuk maluktuk is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2012
Posts: 5 maluktuk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 4 m 31 sec
Reputation Power: 0
Multiple Joins Formatting

Here is the basic setup. I have three tables (orders, customers, CC authorizations) and I'm trying to get a listing of all orders that were entered for customers with credit card terms but for which a credit card was not authorized. I started with a different query (that worked) but only used the customer and orders tables, but now I am getting an error. I suspect the problem lies in the format of my JOIN statements. Any help is greatly appreciated.

Code:
SELECT ct.ordno AS "Order", c.armname AS "Customer", ct.ordamt AS "Total", (ct.ordamt - ct.costamt) AS "Margin", c.termscode AS "Terms", cc.approved AS "Approved?"
  FROM customer AS c
   JOIN ordrhist AS ct, accauth AS cc
      ON c.armacct = ct.acct_no, ct.ordno = cc.ordno
WHERE
ct.orddate = curdate() - 0 AND SUBSTRING(ct.status,1,1)<>'C'AND SUBSTRING(ct.status,2,1)='O' AND ct.hold <> 'Y' AND ct.complete <> 'I' AND c.termscode = 12
ORDER BY ordno

Reply With Quote
  #2  
Old August 13th, 2012, 09:39 AM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 26,377 r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 2 Days 7 h 41 m 20 sec
Reputation Power: 4140
Code:
SELECT ct.ordno AS "Order"
     , c.armname AS "Customer"
     , ct.ordamt AS "Total"
     , ct.ordamt - ct.costamt AS "Margin"
     , 12 AS "Terms"
     , cc.approved AS "Approved?"
  FROM ordrhist AS ct
INNER  
  JOIN customer AS c
    ON c.armacct = ct.acct_no
   AND c.termscode = 12
INNER
  JOIN accauth AS cc
    ON cc.ordno = ct.ordno
 WHERE ct.orddate = curdate() - 0 
   AND SUBSTRING(ct.status,1,1) <> 'C'
   AND SUBSTRING(ct.status,2,1) = 'O' 
   AND ct.hold <> 'Y' 
   AND ct.complete <> 'I' 
ORDER 
    BY ct.ordno
Comments on this post
maluktuk agrees!
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book

Reply With Quote
  #3  
Old August 13th, 2012, 11:07 PM
maluktuk maluktuk is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2012
Posts: 5 maluktuk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 4 m 31 sec
Reputation Power: 0
This worked perfectly. Thank you for your help.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > Multiple Joins Formatting

Developer Shed Advertisers and Affiliates



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

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


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap