开发者

get data in sql from from date to to date

开发者 https://www.devze.com 2023-02-08 04:00 出处:网络
I want to write the stored procedure which would give me the data within the rage of date. I can not use \'Between\', it is giving data between the range , i need within the range means from 1-jan-201

I want to write the stored procedure which would give me the data within the rage of date. I can not use 'Between' , it is giving data between the range , i need within the range means from 1-jan-2011 to 30-jan-2011 (data of 30 jan must be in开发者_开发知识库cluded) how to do this with query/ SP


SELECT ... FROM ... WHERE somecol >= '2011-01-01' AND somecol <= '2011-01-30'


You can use a ">= AND <" condition instead of BETWEEN.

Assuming you pass in @DateTo as the end date you want to INCLUDE:

SELECT Something
FROM YourTable
WHERE DateField >= @DateFrom
    AND DateField < DATEADD(dd, 1, @DateTo)

e.g. pass in @DateFrom = '20110101' and @DateTo = '20110130' then this will return all records from 1st Jan to 30th Jan inclusive.

0

精彩评论

暂无评论...
验证码 换一张
取 消