SQL Server的查询日期 [英] SQL Server date query

查看:179
本文介绍了SQL Server的查询日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新的发展,想知道专业的方式来处理SQL Server中的日期。在我的应用程序主要是我们处理的数据类型日期和时间部分没有问题。同时保持格式DD / MM / YYYY

I am new to development and want to know the professional way to deal with dates in SQL Server. In my applications mainly we deal with the DATE datatype and no concern with time part. Also maintaining the format dd/mm/yyyy

因此​​,举例来说,如果我有表结构如下。

So for example if I have the table with the following structure.

EmployeeTable  
---------------
emp_id int  
emp_name varchar(50)  
join_date date  

如果我想在开始日期和结束日期之间的查询join_date,并通过DD / MM / YYYY作为存储过程的标准,并希望查询。

and if I want to query "join_date" in between start date and end date and pass the dd/mm/yyyy as stored procedure criteria and want to query.

什么是处理日期以专业的方式?我总是转换日期为varchar,然后做我的猜测是做的不专业的方式进行比较。所以,请指导如何使用的例子做的过程中我会AP preciate。

What is the professional way to handle dates? I always convert date in varchar and then do the comparison which I guess is the unprofessional way of doing it. So please guide how to do it in procedure with example I would appreciate.

推荐答案

SQL处理日期就好了,这样你就不会需要将日期转换。

SQL handles dates just fine, so you do not need to convert the dates.

如果您在参数 日期<合格/ code> 类型,那么你不会有任何问题:

If you pass in the parameters as date types, then you will have no problem:

CREATE PROCEDURE myProc 
    @start date, 
    @end date 
AS 
    SELECT emp_id, emp_name, join_date
    FROM EmployeeTable
    WHERE join_date BETWEEN start AND end;

这篇关于SQL Server的查询日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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