如何在一个日期具有特定值的日期之前带回所有记录? [英] How do I bring back all records by date where one date has a certain value?

查看:80
本文介绍了如何在一个日期具有特定值的日期之前带回所有记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含日期的表和一个将日期链接到类型的外键。



大多数日期属于类型1但偶尔会有一个日期将是一个类型2.



我希望SQL查询返回日期中的所有记录,如果其中一个是类型2.



我现在有精神障碍,所以我在这里张贴,看看是否有人可以帮我解决,而我一直在思考,如果不是我会尽快更新答案我设法得到它。



我尝试过:



我尝试制作一个与类型2匹配的日期列表,然后查询以返回列表中每个日期的所有记录。我只是很难将它们放入一个DataTable中,我确信无论如何都有一个更好的查询方式。

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.

推荐答案

构建查询SQL Server,将其移动到存储过程(或构建视图),并从您的代码中调用它。这样会更容易。



除此之外,如果没有表格模式的相关部分并且描述如何使用日期时间,我们无法真正帮助您确定记录的类型。
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.


这篇关于如何在一个日期具有特定值的日期之前带回所有记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆