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
 General SQL Server Forums
 New to SQL Server Programming
 Query help

Author  Topic 

jim_jim
Constraint Violating Yak Guru

306 Posts

Posted - 2012-09-25 : 14:19:19
I am trying to write a select statement to get all requests from a table customerinfo where count of the reqno is greater than 1 and in every unique reqno there should be atleaset one reportid with an Id 1873 and the other reportids can be anything between (456,457,458,459,460)

Iam not sure how i put sql together for the above but the sample data will look like this

Reqno ReportId
111111 1873
111111 460
111111 457
222222 1873
222222 456
333333 456
333333 1873
333333 460
333333 459


Thanks

robvolk
Most Valuable Yak

15732 Posts

Posted - 2012-09-25 : 14:22:34
SELECT ReqNo FROM customerinfo WHERE ReportID=1873
INTERSECT
SELECT ReqNo FROM customerinfo WHERE ReportID BETWEEN 456 AND 460
Go to Top of Page

jim_jim
Constraint Violating Yak Guru

306 Posts

Posted - 2012-09-25 : 14:44:19
Thank You
quote:
Originally posted by robvolk

SELECT ReqNo FROM customerinfo WHERE ReportID=1873
INTERSECT
SELECT ReqNo FROM customerinfo WHERE ReportID BETWEEN 456 AND 460

Go to Top of Page
   

- Advertisement -