views:

25

answers:

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!

+1  A: 

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
Lieven
in single query i need ...plz
jay
A: 

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.

marc_s

related questions