Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6789293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:35:11+00:00 2026-05-26T17:35:11+00:00

Looking for some directions on what options I should be considering for the following

  • 0

Looking for some directions on what options I should be considering for the following problem of creating a select statement (SQL SERVER) based on conditions:

NOTE: simplifying the actual problem

If I have two tables, each with a field I need to use
EXAMPLE:

CUSTOMER.CUSTOMER_ID
PRODUCT.PRODUCT_ID

I have 2 other tables that hold special product pricing based on these two fields
EXAMPLE:

CUSTOMER_PRICING 
***************************************
* CUSTOMER_ID  * PRODUCT_ID  * PRICE  *
*                                     *
*     ABC      *    100      *  5.00  *
***************************************

MARKET_PRICING 
***************************************
* CUSTOMER_ID  * PRODUCT_ID  * PRICE  *
*                                     *
*     ACME      *    200      *  7.00 *
***************************************

For every CUSTOMER.CUSTOMER_ID and PRODUCT.PRODUCT_ID I want to join CUSTOMER_PRICING and MARKET_PRICING records using a left outer join. But the conditions are only if

A) the PRICE field is not null

B) and if a CUSTOMER_ID/PRODUCT_ID exists in both, I only want the record from CUSTOMER_PRICE

Something like:

IF EXISTS (SELECT C.CUSTOMER_ID, P.PRODUCT_ID FROM CUSTOMER C, PRODUCT P 
           WHERE C.CUSTOMER_ID, P.PRODUCT_ID IN 
           (SELECT PRICE FROM CUSTOMER_PRICE WHERE PRICE IS NOT NULL))
ELSE IF EXISTS 
          (SELECT C.CUSTOMER_ID, P.PRODUCT_ID FROM CUSTOMER C, PRODUCT P 
           WHERE C.CUSTOMER_ID, P.PRODUCT_ID IN 
           (SELECT PRICE FROM MARKET_PRICE WHERE PRICE IS NOT NULL))

***then somehow do a join on these results…..

Any Suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T17:35:12+00:00Added an answer on May 26, 2026 at 5:35 pm

    Creating a view called CMPricing would greatly simplify this situation.

    CREATE VIEW CMPricing
    AS
    SELECT t1.CUSTOMER_ID, t1.PRODUCT_ID, t1.PRICE AS CUSTOMER_PRICE t2.PRICE AS MARKET_PRICE
    FROM CUSTOMER_PRICING t1 INNER JOIN MARKET_PRICING t2 ON t1.CUSTOMER_ID = t2.CUSTOMER_ID AND t1.PRODUCT_ID = t2.PRODUCT_ID
    WHERE t1.PRICE IS NOT NULL AND t2.PRICE IS NOT NULL


    Then you query this view to get what you want.

    This view will contain only the data that is common between both “PRICE” tables where both “PRICE” values are not null. This view in essence does the filtering for you which in turn makes your queries with the other data tables easier to do and understand.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Looking at some assembly code for x86_64 on my Mac, I see the following
I'm looking for some direction on a script that I'd like to build. Essentially,
I'm just looking for some direction when it comes to NHibernate and WCF. At
I'm fiddling with a bit of c++/opencv. I was looking some of the samples
Looking at some of the code System.Linq I've come across some examples of Buffer<TSource>
Looking for some advice on the best way to implement localization along with client
Looking for some guidance on a WCF service I’m prototyping. I have a WCF
Looking for some resources on SOA / BPEL best practices. Specially BPEL.
Looking for some help! I need to split a string at the last occurrence
looking for some help with images referenced within the stylesheet. I have no problems

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.