如何创建存储过程? [英] How to create stored procedure?

查看:86
本文介绍了如何创建存储过程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果给定的两个日期不同,如何创建用于获取两个日期之间所有日期的存储过程.

如果这两个日期相同,那么我想访问ASP.NET中快速数据库中的所有事件.

How to create stored procedure for fetching all dates between two dates, if given two dates are different.

If that two dates are same, then I want to access all it''s events in express database in ASP.NET

推荐答案

/>
create PROCEDURE testdate @date1 datetime, @date2 datetime
AS
if(@date1!=@date2)begin
SELECT datecreated FROM tablename WHERE datecreated BETWEEN @date1 AND @date2
end
else
begin
select * from tablename
end


select * 
from table
where table.DateColumn >= @StartDate AND table.DateColumn <= @EndDate


在使用比较运算符比较日期类型时,您需要格外小心.

http: //www.texastoo.com/post/2010/09/04/Comparison-operators-in-TSQL-for-Dates-3c-3e-3c3d-3e3d-BETWEEN.aspx [ http://msdn.microsoft.com/en-us/library/ms189794.aspx [ ^ ]
You need to be extra careful while using comparison operators for comparing date types.

http://www.texastoo.com/post/2010/09/04/Comparison-operators-in-TSQL-for-Dates-3c-3e-3c3d-3e3d-BETWEEN.aspx[^]

You can also give a try to DateDiff in case it fits in your scenario.
http://msdn.microsoft.com/en-us/library/ms189794.aspx[^]


这篇关于如何创建存储过程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆