Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 float datatype

Author  Topic 

shm
Yak Posting Veteran

86 Posts

Posted - 2008-10-30 : 06:50:23
hi,

am trying to get only time from one of the col varchar(20) datatype.
for ex +0 07:49:27.0000 from this am getting only 7:45 wt i am doing is converting this to float for some calculation..but for 9.00 and 8.30 instead of this it is coming 9 and 8.3 respectively it shld not come like this..i tried in diff ways am not getting the correct result..what i shld do for this?

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2008-10-30 : 07:09:42
What type of calculations are you trying to do? If you want to calculate times or dates, use the dateadd() function. If you think 8:30, should be 8.5, you'll have to do your own conversions.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-30 : 07:37:41
why have you chosen varchar field for storing datetime values?always try to use proper datatype for fields. that would make manipulations much easier.
Go to Top of Page

shm
Yak Posting Veteran

86 Posts

Posted - 2008-10-30 : 07:40:07
thank u for ur reply

but hw shall i give that dateadd() func becoz the col varchar datatype
Convert(float,Substring(time_in,4,2)) +(Convert(float,Substring(time_in,7,2))/100) As Time_In
this is one am doing, in time_in col hrs and min i il get from this...but as i ltd earlier,if it 9 hrs it shld come as 9:00 and also 8:3 means 8:30
Go to Top of Page

shm
Yak Posting Veteran

86 Posts

Posted - 2008-10-30 : 07:43:53
i have not done that...some one else given as varchar datatype for the time...
nw i cann't change that datatype...so am trying to get the data by changing the datatype not in the table in the query am trying...
Go to Top of Page

rohitkumar
Constraint Violating Yak Guru

472 Posts

Posted - 2008-10-30 : 09:47:34
where's the "." in your query?
Go to Top of Page
   

- Advertisement -