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
 General SQL Server Forums
 New to SQL Server Programming
 Convert text into INT

Author  Topic 

DHL
Starting Member

16 Posts

Posted - 2008-05-27 : 07:29:47
Hi,

I have a column with records as follows:

5 days
7 days
15 days
20 days
30 days
60 days
100 days
120 days

How can I only take out only the numeric part and make sure that this will be displayed as value as I have to make calculations using that value...

Please help

Thanks!

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-05-27 : 07:33:49
SELECT CAST(LEFT(value,CHARINDEX(' ',Value)-1) AS int) from table.
If you're not sure whether you'll have space in all fields you need to check it using CASE WHEN
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-05-27 : 07:45:33
or you can even use PARSENAME function

SELECT COALESCE(PARSENAME(REPLACE(value,' ','.'),2),PARSENAME(REPLACE(value,' ','.'),1)) FROM Table
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-05-27 : 08:24:21
SELECT REPLACE(Col1, ' days', '')
FROM Table1



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

DHL
Starting Member

16 Posts

Posted - 2008-05-27 : 09:20:53
Visakh16,

can you please clarify more in detail? The name of the column is 'payment_terms'

Thanks!
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-05-27 : 09:50:39
quote:
Originally posted by DHL

Visakh16,

can you please clarify more in detail? The name of the column is 'payment_terms'

Thanks!


SELECT COALESCE(PARSENAME(REPLACE(payment_terms,' ','.'),2),PARSENAME(REPLACE(payment_terms,' ','.'),1)) FROM Table

Did you try the suggested methods?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -