如何将 ISNULL 和 GETDATE 实现到 DATEDIFF 语句中

发布于 2024-12-14 05:47:12 字数 493 浏览 2 评论 0原文

“如果返回日期为 NULL,则该列应使用 ISNULL 和 GETDATE 来计算当前租赁期限。(即,如果没有返回日期,则使用当前日期。)” 目前,这是我迄今为止已完成的代码片段,我需要创建一个 ISNULL 和 GETDATE 语句以与租赁期限一起使用。我不确定是否需要使用 IF 语句或在当前配置中将所述语句放在何处。

SELECT mo.Movie_ID                     
 , co.copy_id                      
 , mo.Movie_Name
 , fo.format_name                  
 , c.customer_id
 , rental_ID
 , DATEDIFF (day, rental_date, return_date) AS rental_duration
 , c.first_name + ' ' + c.last_name AS customer_name

提前致谢。任何帮助将不胜感激。

"the column should use ISNULL and GETDATE to calculate the current rental duration if the return date is NULL. (i.e. if there is no return date, use the current date.)"
Currently this is the snippet of code i have so far completed, i need to create a ISNULL and GETDATE statement for use with rental duration. i am not sure if i need to use an IF statement or where to put said statement in my current configuration.

SELECT mo.Movie_ID                     
 , co.copy_id                      
 , mo.Movie_Name
 , fo.format_name                  
 , c.customer_id
 , rental_ID
 , DATEDIFF (day, rental_date, return_date) AS rental_duration
 , c.first_name + ' ' + c.last_name AS customer_name

Thanks in advance. any help would be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

戒ㄋ 2024-12-21 05:47:12
SELECT mo.Movie_ID                     
 , co.copy_id                      
 , mo.Movie_Name
 , fo.format_name                  
 , c.customer_id
 , rental_ID
 , DATEDIFF (day, rental_date, ISNULL(return_date,GETDATE())) AS rental_duration
 , c.first_name + ' ' + c.last_name AS customer_name

应该可以做到这一点。

SELECT mo.Movie_ID                     
 , co.copy_id                      
 , mo.Movie_Name
 , fo.format_name                  
 , c.customer_id
 , rental_ID
 , DATEDIFF (day, rental_date, ISNULL(return_date,GETDATE())) AS rental_duration
 , c.first_name + ' ' + c.last_name AS customer_name

That should do it.

风吹过旳痕迹 2024-12-21 05:47:12

ISNULL 是一个内联语句,当源列不为空时,返回该列;当源列为空时,返回替代值。

SELECT ISNULL(return_date, getdate()) ...

当return_date为null时,调用函数getdate()返回正确的值。

ISNULL is an inline statement which, when the source column is not null, returns that column and when it is null, returns an alternate value.

SELECT ISNULL(return_date, getdate()) ...

When return_date is null, the function getdate() is called to return the proper value.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文