Click here to Skip to main content
14,970,515 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I have one table names is "tblRequestEmployeePTOsToAdmin" and column names
ID int,
 FromDate (datetime),
ToDate	(datetime),
SubmitDate (datetime),
HoursForDay (int),
TotalRequestHours(int),

table values is
ID |Fromdate        |       Todate      |        SubmitDate    |      HrsForday |   TotalReqhrs
12 |     2013-02-20 |      2013-02-23|  2013-02-20    |        3	       |   12


My out put like this
ID | Fromdate   |  SubmitDate       |    HrsForday   |  TotalReqhrs
12 | 2013-02-20  |  2013-02-20     |        3	     |    12
12 | 2013-02-21  | 2013-02-20      |       3	     |     12
12 | 2013-02-22  | 2013-02-20      |       3	     |     12
12 | 2013-02-23  |  2013-02-20     |        3	     |     12


so how to write query for display this format

please help me..

thanks
Posted
Updated 15-Apr-13 21:37pm
v4

1 solution

There are several ways to achieve that. Please, see below examples:
SQL
SELECT *
FROM TableName
WHERE FromDate BETWEEN @dateFrom AND @dateTo


SQL
SELECT *
FROM TableName
WHERE ToDate BETWEEN @dateFrom AND @dateTo


SQL
SELECT *
FROM TableName
WHERE Submitdate BETWEEN @dateFrom AND @dateTo


SQL
SELECT *
FROM TableName
WHERE FromDate>= @dateFrom AND SubmitDate <=@dateTo


[EDIT #1]
If you want to get date difference, use DATEDIFF[^] function or CONVERT[^] function to substract date diffs as integer.

SQL
SELECT *
FROM TableName
WHERE DATEDIFF(dd, FromDate, ToDate)<=2


SQL
SELECT *
FROM TableName
WHERE CONVERT(INT, FromDate - ToDate)<=2
[/EDIT]
   
v2
Comments
Santhosh23 16-Apr-13 3:52am
   
hi Macieij. thanks for your replay.
i have only one record in my table. the record dived into multiple rows based on from-date and to-date differnces
Maciej Los 16-Apr-13 4:00am
   
I'm not sure what you want to achieve, but see my answer after update.
Santhosh23 16-Apr-13 4:31am
   
just now execute your query display record between two dates
Maciej Los 16-Apr-13 5:18am
   
and...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900