Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
|
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 23rd, 2003, 08:01 PM
Registered User
 
Join Date: Jun 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to mgibson30
Default Help with 2 table SQL Query

I have a small problem with price lists in SQL.

I have one table with fields Item_num,item_cost,item_price

In another table I would like to apply special prices for specific Items in the main price list table. The structure of the 2nd table is

Account_num (Related to the customer account)
Item_num
disc_item_price

I would like to be able to execute an sql statement against both tables and return all items for a particular account number that are actively discounted and all other items from the standard price list (excluding the list prices of items that have discounts applied)

Can anyone help????????

Thanks
 
Old June 23rd, 2003, 08:38 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
Default

How about:
Code:
SELECT @Account_num, SP.Item_num, COALESCE(DP.disc_item_price,SP.item_price)
   FROM Std_prices SP LEFT JOIN Disc_prices DP
      ON SP.Item_num=DP.Item_num
     AND DP.Account_num=@Account_num;
Jeff Mason
Custom Apps, Inc.
www.custom-apps.com
 
Old June 23rd, 2003, 10:32 PM
Registered User
 
Join Date: Jun 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to mgibson30
Default

Works perfectly! Thanks for your prompt response.



Quote:
quote:Originally posted by Jeff Mason
 How about:
Code:
SELECT @Account_num, SP.Item_num, COALESCE(DP.disc_item_price,SP.item_price)
   FROM Std_prices SP LEFT JOIN Disc_prices DP
      ON SP.Item_num=DP.Item_num
     AND DP.Account_num=@Account_num;
Jeff Mason
Custom Apps, Inc.
www.custom-apps.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic Table Name in SQL Query drani C# 2 November 6th, 2007 05:47 PM
Nested Loops in SQL Query values from table/set miamikk SQL Server 2000 1 August 31st, 2007 12:35 AM
Update table using SQL query from form pater53 Access VBA 4 January 24th, 2007 11:24 AM
How to pass Table Name as a parameter in SQL query visualbrin Reporting Services 1 October 13th, 2006 04:08 PM
Error on Make-Table Query In Union Query rylemer Access 1 August 20th, 2003 07:42 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.