January 8, 2008 at 9:10 am
I have time field in milliseconds.
when its entered as 5.7 from the app it is saved as 2052000 in the DB. it shows that the value is div by 360000.
when am trying to convert millisec value back into original am getting the round number instead of decimal(5.7)
what conversion i need to use here?
January 8, 2008 at 10:46 am
You can cast either number as a float like:
select seconds = cast(2052000 as float) / 360000
or
select seconds = 2052000 / cast(360000 as float)
January 8, 2008 at 10:50 am
Adding to that..
How can i make sure that after decimal point there should be only 1 digit?
January 8, 2008 at 11:06 am
Just use the round function:
select seconds = round(2100045 / cast(360000 as float),1)
January 8, 2008 at 11:36 am
I dont need a round value, what i need is
I have to enforce a constraint where the user has to enter only 1 digit after decimal point, if its entered like 0.65 then it is an error. it shud be 0.6 only.
January 8, 2008 at 12:08 pm
Sorry, will this work? (note the one less zero on the 360000)
select seconds = cast((2287045 / 36000) as float) / 10
January 8, 2008 at 12:12 pm
the conversion part is working fine.
i just want to find fields where there is a value more than one digit after decimal point
January 8, 2008 at 12:47 pm
Is this what you are looking for?
declare @temp as table (t int)
insert into @temp
select 234000 --.65
union all
select 2052000 -- 5.7
union all
select 1638000 -- 4.55
union all
select 1620000 -- 4.5
select *,seconds = t / cast(360000 as float)
from @temp
where t % cast(36000 as decimal) > 0
January 8, 2008 at 1:44 pm
no its not working t sort out rows which has more than 1 digit after decimal point
January 8, 2008 at 1:46 pm
Did you try my sample code? Does it work for you? What does your query look like?
January 8, 2008 at 1:53 pm
your sample code is not working for me.
i just need to find out rows that has more than 1 digit after decimal point
January 8, 2008 at 6:09 pm
Adrienne (1/8/2008)
Is this what you are looking for?declare @temp as table (t int)
insert into @temp
select 234000 --.65
union all
select 2052000 -- 5.7
union all
select 1638000 -- 4.55
union all
select 1620000 -- 4.5
select *,seconds = t / cast(360000 as float)
from @temp
where t % cast(36000 as decimal) > 0
Seriously... it's not working... try your own code and see the errors it generates...
--Jeff Moden
Change is inevitable... Change for the better is not.
January 8, 2008 at 6:15 pm
This will do it...
declare @temp table (t int)
insert into @temp
select 234000 --.65
union all
select 2052000 -- 5.7
union all
select 1638000 -- 4.55
union all
select 1620000 -- 4.5
select *, t/36000.0 ,t/36000
from @temp
WHERE t/36000<>t/36000.0
--Jeff Moden
Change is inevitable... Change for the better is not.
January 9, 2008 at 6:38 am
am not sure if am explaining it correctly..let me try again
I have time in millisec like 630000 in my DB for which it was entered as 1.75 from the app by the user.
but I want to restrict user to enter only 1.7 instead of1.75. if the user enters the value as 1.75 then i want to raise error.
That means 1st I have to find the value in DB (630000) and convert it into decimal which becomes 1.75, as it has more than 1 digit after decimal point I have to raise error, after converting if it comes to 1.7 then its a good value else an error.
January 9, 2008 at 6:44 am
Forcing a data entry mask (your "no more than 1-digit after decimal point") is a UI issue. The database server has no control over how data is entered. You should enforce your rule in whatever application you're using to let the users enter the data.
----------------------------------------------------------------------------------
Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
Viewing 15 posts - 1 through 15 (of 21 total)
You must be logged in to reply to this topic. Login to reply