August 10, 2010 at 10:02 am
Can anyone help me on following string manipulation?
Basically i want to trucate the digits before decimal point and select rest of the part with decimal.
I have the query as follows:
SELECT SALESTABLE.salesid,SALESTABLE.MODIFIEDTIME, SALESTABLE.MODIFIEDTIME/60/60 as hour,
(CAST(SALESTABLE.MODIFIEDTIME AS float)/3600)
FROM SALESTABLE
where (SALESTABLE.SALESID = N'SO1000863')
select .8061111111111*60 // Need to be able to do this in above query dynamically
Result1:
salesid MODIFIEDTIMEhour(No column name)
SO1000863389021010.8061111111111
Result2:
48.3666666666660
August 10, 2010 at 10:12 am
is it really string manipulation?
if it's a float/decimal, you could subtract the FLOOR() of the value from itself to get the remainder:
declare @val float
set @val = 10.8061111111111
SELECT @val - floor(@val)--returns 0.8061111111111
--if it's a string?!?!
declare @val2 varchar(30)
set @val2 = '10.8061111111111'
SELECT convert(float,@val2) - floor(convert(float,@val2))--returns 0.8061111111111
Lowell
August 10, 2010 at 10:15 am
DECLARE @test-2 AS DECIMAL(19,11)
SET @test-2 = 55.32178699281
SELECT @test-2
,SUBSTRING(CONVERT(VARCHAR(MAX),@TEST),CHARINDEX('.',@TEST),LEN(@TEST))
,CONVERT(DECIMAL(19,11),SUBSTRING(CONVERT(VARCHAR(MAX),@TEST),CHARINDEX('.',@TEST),LEN(@TEST)))*60
/*
55.32178699281.3217869928119.30721956860
*/
August 10, 2010 at 10:21 am
Thanks Lowell.
Floor worked for me.
SELECT SALESTABLE.salesid,SALESTABLE.MODIFIEDTIME, SALESTABLE.MODIFIEDTIME/60/60 as hour,
((CAST(SALESTABLE.MODIFIEDTIME AS float)/3600) -floor((CAST(SALESTABLE.MODIFIEDTIME AS float)/3600)))*60
FROM SALESTABLE
where (SALESTABLE.SALESID = N'SO1000863')
Result
salesidMODIFIEDTIMEhourminute
SO1000863389021048.3666666666667
August 10, 2010 at 10:22 am
Skcadavre,
Thanks for your reply
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply