Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Other SQL Server 2008 Topics
 Querry

Author  Topic 

nord
Posting Yak Master

126 Posts

Posted - 2013-04-09 : 13:57:31
Hi,
I have data of invoices and each invoice have 2 status (2 line)sale and billed
How I can select invoice which have status sale but dont have status billed
Thanks

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-04-09 : 14:54:10
[code]
SELECT *
FROM
(
SELECT *,SUM(CASE WHEN status='billed' THEN 1 ELSE 0 END) OVER (PARTITION BY InvoiceID) AS Cnt
FROM table
)t
WHERE Cnt =0
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

nord
Posting Yak Master

126 Posts

Posted - 2013-04-09 : 15:37:44
Thanks
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-04-10 : 00:50:59
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -