如何将 ISNULL 和 GETDATE 实现到 DATEDIFF 语句中
“如果返回日期为 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
应该可以做到这一点。
That should do it.
ISNULL 是一个内联语句,当源列不为空时,返回该列;当源列为空时,返回替代值。
当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.
When return_date is null, the function getdate() is called to return the proper value.