SQL Server DateAdd问题 [英] SQL Server DateAdd problem
问题描述
你好朋友,
我需要SQL Server帮助.
我有一个包含两列的表1)开始日期2)结束日期
示例数据如下.
StartDate EndDate
1/5/2010 1/5/2010
1/6/2010 1/6/2010
2010年1月7日null
2010年1月8日null
1/9/2010 null
1/10/2010空
1/11/2010空
2010年1月12日2010年12月1日
1/13/2010 null
如果结束日期不为null,则为假期;如果结束日期为null,则为工作日期.我的要求是,如果用户输入的选择1/5/2010并输入4作为值,那么我需要向该特定选择的日期添加4天,其中结束日期不为空,因此上述日期将为1/10/2010.
任何人都可以帮我写一个sql查询或过程.我将从用户那里得到的值是startdate&no.要添加的天数.
谢谢,
mohan
Hello Friends,
I need help in sql server.
I have a table with two columns 1) startdate 2) enddate
sample data will be like below.
StartDate EndDate
1/5/2010 1/5/2010
1/6/2010 1/6/2010
1/7/2010 null
1/8/2010 null
1/9/2010 null
1/10/2010 null
1/11/2010 null
1/12/2010 1/12/2010
1/13/2010 null
if the enddate is not null then it is holiday, if the end date is null it is working date. my req is if the user enters selects 1/5/2010 and enters 4 as value then i need to add 4 days to that particular selected date where the end date is not null, so with the above date it will be 1/10/2010.
can anybody help me out to write a sql query or procedure for that. values i will get from user is startdate & no. of days to add.
thanks,
mohan
推荐答案
为什么不在日期时间类中使用AddDays方法?您可以在SQL中执行此操作,但是为什么需要这样做?
Why not use the AddDays method in the date time class ? You can do this in SQL, but why do you need to ?
克里斯,
我们正在使用销售门户,我们想显示商品何时到达.
这就是我要在工作日向用户选择的日期添加天数的原因.
谢谢,
Mohan
Hi Chris,
We are using sales portal and we want to show when the item will arrives.
that is the reason i want to add days to the user selected date if it is a working day.
thanks,
Mohan
请编辑您的问题,不要添加包含更多问题的虚假答案.
我看不出这会如何改变我的回应.为什么您需要在SQL中添加天数,而不是在调用存储过程的代码中添加天数?根据MSDN,在SQL Server中,可使用+运算符来添加天数.使用google,还花了我3秒钟的时间来找到此 [ ^ ].但是,我仍然不明白为什么您需要使proc复杂化而不在代码中生成日期范围.
Please edit your question, not add a fake answer that is more questions.
I don''t see how that changes my response. Why do you need to add days in SQL and not in your code that calls the stored proc ? According to MSDN, in SQL Server the + operator can be used to add days. Using google, it also took me 3 seconds to find this[^]. However, I still don''t see why you need to complicate your proc and not generate your date range in your code.
这篇关于SQL Server DateAdd问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!