简体   繁体   English

如何仅从SQL Server的XML列中检索日期大于今天的日期的行?

[英]How can I only retrieve rows with dates greater than today's date from an XML column in SQL Server?

I want to only return rows that have a date in the XML column after the current date in SQL Server. 我只想返回在SQL Server中当前日期之后在XML列中具有日期的行。 How can i do this? 我怎样才能做到这一点?

The error i receive for the last line below is: XQuery [LB_Webinar.WebinarXML.exist()]: There is no function '{ http://www.w3.org/2004/07/xpath-functions }:GETDATE()' 我收到的以下最后一行错误是: XQuery [LB_Webinar.WebinarXML.exist()]:没有函数'{ http://www.w3.org/2004/07/xpath-functions }:GETDATE() “

(
   @Site varchar(10)
)

AS

WITH XMLNAMESPACES ('http://www.testsite.com/ClientWebinar' as lbx)

SELECT * FROM LB_Webinar 

WHERE

Site = @Site

AND

LB_Webinar.WebinarXML.exist('/lbx:CLIENT_WEBINAR/lbx:WEBINAR/lbx:WEBINARDATE > GETDATE()') = 1

XML Code: XML代码:

<lbx:CLIENT_WEBINAR xmlns:lbx="http://www.testsite.com/ClientWebinar">
    <lbx:WEBINAR>
        <lbx:WEBINARDATE>6/18/2013 2:00:00 PM</lbx:WEBINARDATE>
    </lbx:WEBINAR>
</lbx:CLIENT_WEBINAR>

You can store today's datetime value in a variable and use sql:variable() in your expression to use the variable in the comparison. 您可以将今天的datetime值存储在变量中,并在表达式中使用sql:variable()在比较中使用该变量。

DECLARE @Today DATETIME;
SET @Today = GETDATE();

WITH XMLNAMESPACES ('http://www.testsite.com/ClientWebinar' as lbx)
SELECT *
FROM LB_Webinar 
WHERE LB_Webinar.WebinarXML.exist('/lbx:CLIENT_WEBINAR/lbx:WEBINAR/lbx:WEBINARDATE/text()[. > sql:variable("@Today")]') = 1;

Note: the above code works if you change your datetime values to ISO8601 yyyy-mm-ddThh:mi:ss.mmm . 注意:如果将datetime值更改为ISO8601 yyyy-mm-ddThh:mi:ss.mmm则上述代码有效。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 Microsoft SQL Server 2008 获取日期比今天的日期大 6 个月的所有记录? - How do I get all records where date is 6 months greater than today's date, using Microsoft SQL Server 2008? 知道如何从今天的日期检索属于前一周的日期吗? - Any idea how can i retrieve dates that belong to the week before from today's date? 如何只存储日期时间的日期部分。 今天属性到SQL Server表的datetime列? - How can I store only the date portion of the datetime. Today property to a SQL Server table datetime column? 从带有时间戳的时间戳列中检索只有今天的日期的记录 - Retrieve only records with today's date from an epoc timestamped column 如何在 SQL 服务器中查询大于特定日期的所有日期? - How do I query for all dates greater than a certain date in SQL Server? 我如何在sql server中按特定日期检索行? - how i can retrieve rows by specific date in sql server? 如何从日期(格式星期一)大于今天的行中获取数据 - how to get data from rows where date(format monyy) is greater than today 如何包含列值大于使用内部连接的 SQL 查询中返回的值的行? - How can I include rows with a column value greater than what is returned in a SQL query that utilizes inner joins? SQL Server 创建日期大于一个日期的标志 - SQL Server creating a flag with dates greater than one date 从今天起检索加入日期少于 15 天的行 - Retrieve rows with joining date less than 15 days from today
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM