SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Query help
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

jim_jim
Constraint Violating Yak Guru

USA
299 Posts

Posted - 09/25/2012 :  14:19:19  Show Profile  Reply with Quote
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

USA
15663 Posts

Posted - 09/25/2012 :  14:22:34  Show Profile  Visit robvolk's Homepage  Reply with Quote
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

USA
299 Posts

Posted - 09/25/2012 :  14:44:19  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.12 seconds. Powered By: Snitz Forums 2000