Click here to Skip to main content
15,917,060 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
select  (select dtleavefrom from dilpreet.leavedetails minus select dtleaveto from dilpreet.leavedetails) as newcol from dilpreet.leavedetails
Posted
Comments
Maciej Los 8-Jul-13 5:09am    
What are you trying to achieve?
Do you want to get the difference between dates?
Please, be more specific and provide more details.

SQL
select (dtleavefrom - dtleaveto ) as newcolumn
from dilpreet.leavedetails 
 
Share this answer
 
Comments
Adarsh chauhan 5-Jul-13 8:24am    
sorry to say but It would give wrong output as you can see that dtleavefrom and dtleaveto must be date.
Kuthuparakkal 5-Jul-13 8:29am    
did user tell you that ? Let him comeback with proper datatypes..
I am very poor in guessing the datatypes used by user; no super-natural abilities, sorry!
Adarsh chauhan 5-Jul-13 8:37am    
ya you are right user has not mentioned any datatype, but just said because it is but obvious that when we talk about leavefrom and leave to we talk about days.
above will work with numeric data.

I didn't mean to be rude..
Kuthuparakkal 5-Jul-13 12:05pm    
I was making my point, no offence... carry on..
Hi,

you can use the following for your purpose

SQL
create table test (fromDate datetime, Todate DateTime)

insert into test values('15-july-2013','16-july-2013')
insert into test values('1-july-2013','10-july-2013')

select *,DATEDIFF(day,fromDate,Todate)+1 as LeavesBetweenRangefrom test



I have added +1 because i am including both the days when counting no. of leaves
 
Share this answer
 
v3
select (dtleaveto-dtleavefrom) as newcol from dilpreet.leavedetails

Note :- i think dtleaveto is at first Place in above statement.
 
Share this answer
 
Hi Frnd,

SQL
select dtleavefrom,dtleaveto,(dtleaveto-dtleavefrom) newcol
from dilpreet.leavedetails


Use the above script.
 
Share this answer
 

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