2
Cusid  Cusgroupid  Productid
5      NULL        NULL

ppid   cusgroupid       list    bulk     cost   billing
854    NULL             45.00   42.00    42.00  42.00   
855    2                39.00   36.00    33.00  30.00

I want to compare two table, expect result is

1, if cusgroupid is 2 only select that row

ppid   cusgroupid       list    bulk     cost   billing
855    2                39.00   36.00    33.00  30.00

2, if cusgroupid is null only select that row

ppid   cusgroupid       list    bulk     cost   billing
854    NULL             45.00   42.00    42.00  42.00   

Please help!

4
  • 2 condition is if cusgroupid is NULL only select that row ppid cusgroupid list bulk cost billing 854 NULL 45.00 42.00 42.00 42.00 Commented Aug 19, 2010 at 10:29
  • 1
    To be able to help you, we have to understand what you want. I for one don't have a clue, sorry. Commented Aug 19, 2010 at 10:30
  • He wants to join the two tables on cusgroupid I think Commented Aug 19, 2010 at 10:36
  • And this question has already gotten two upvotes, interesting... Commented Aug 19, 2010 at 11:00

2 Answers 2

1

Still not quit sure what you need but does this get you any further?

SELECT * FROM YourTable WHERE cusgroupid = 2
SELECT * FROM YourTable WHERE cusgroupid IS NULL

or perhaps

SELECT   * 
FROM     Table1 t1 
         INNER JOIN Table2 t2 
           ON ISNULL(t2.cusgroupid, -1) = ISNULL(t1.cusgroupid, -1)

or

SELECT * FROM YourTable WHERE cusgroupid = 2 OR cusgroupid IS NULL
Sign up to request clarification or add additional context in comments.

1 Comment

in single query i need ... plz
0

If you want to have all rows with value 2 or NULL, then use:

SELECT ppid, cusgroupid, list, bulk, cost, billing
FROM dbo.YourTable 
WHERE ISNULL(cusgroupid, 2) = 2

This will select all rows with cusgroupid = 2, and if cusgroupid is NULL, it will also use the value 2 - so those are included as well.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.