Click here to Skip to main content
15,921,841 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a table containing Dates and a foreign key linking the date to a type.

The majority of Dates are of type 1 but every now and then one will be a type 2.

I would like an SQL query to return all records from a date if one of them is of type 2.

I am having a mental block right now so i'm posting here to see if anyone can help me out whilst i'm stuck thinking, if not i will update with an answer as soon as i manage to get it.

What I have tried:

I tried making a list of dates that match type 2 then a query to return all records for each date in the list. I'm just having trouble getting them into one DataTable, and i am sure there is a much better one query way to do it anyway.
Posted
Updated 4-Jun-18 4:19am

1 solution

Build the query in SQL Server, move it to a stored procedure (or build a view), and call it from your code. It will be MUCH easier that way.

Beyond that, we can't really help you without the relevant part of your table schemas and a description how the datetime is used to determine the record's type.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900