如何执行日期/月份sql查询

编程入门 行业动态 更新时间:2024-10-27 14:31:56
本文介绍了如何执行日期/月份sql查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

大家好。 我想在我的SQL查询中进行选择。

Hi all . I want to make selection in my sql query .

SELEC DATEADD((CASE WHEN table.date_i = '1' or table.date_i = '4' THEN 'day' ELSE 'month' end as col ), 7 , current_timestamp ) < current_timestamp FROM table

我需要添加7天或7个月取决于 table.datei 值。此查询不起作用。请帮我搞定。 MS SQL SERVER T-SQL

I need to add 7 days or 7 months depend on table.datei values . This query doesn't work . Please help me to make this . MS SQL SERVER T-SQL

推荐答案

试试: Try: SELECT CASE WHEN table.date_i = '1' or table.date_i = '4' THEN DATEADD( dd, 7 , current_timestamp) ELSE DATEADD( mm, 7 , current_timestamp) END AS Col FROM table

怀疑它是否正是你想要的 - 但你的SQL非常奇怪,所以我可以确切地解决你想要做的事情......

Doubt if it'll be exactly what you want - but your "SQL" is seriously odd, so I can;t work out exactly what you are trying to do...

你需要在使用定义间隔的方式上进行小的修改。一种可能性是使用如下结构: You need to make small modifications in the way use define the interval. One possibility is to use structure like the following: DECLARE @intervaltype int; DECLARE @datetouse date SET @datetouse = GETDATE() SET @intervaltype = 1; --SET @intervaltype = 2; SELECT CASE @intervaltype WHEN 1 THEN DATEADD( day, 7, @datetouse) WHEN 2 THEN DATEADD( month, 7, @datetouse) END

在实际情况中,您可以使用某些表中的某些列替换该变量。

In the real situation you would replace the variable with some columns from some table.

更多推荐

如何执行日期/月份sql查询

本文发布于:2023-06-04 22:10:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/506088.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:日期   sql

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!