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
 CHARINDEX Help

Author  Topic 

cnbhold
Starting Member

43 Posts

Posted - 2010-07-30 : 11:57:37
I have SQL table that has software version information. I need a way to convert the following column of data

Version
11.0
10.0
9.0
9
8.0.0.2734
8.0.2
7
7.0
7.0.1
6.0
6.1.2

Convert To

Version
11.x
10.x
9.x
9.x
8.x
8.x
7.x
7.x
7.x
6.x
6.x

Angel

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2010-07-30 : 12:10:34
[code]UPDATE YourTable
SET version = left(version, Abs(charindex('.', version)-1)) + '.x'[/code]
Go to Top of Page

cnbhold
Starting Member

43 Posts

Posted - 2010-07-30 : 13:30:18
This works great only if the version number is for example 7.0 or 7 is converted to 7.x but for 11 without a period is converted to 1
Not sure what to change to get the double digits without a period to convert correctly.

Angel
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-07-30 : 13:54:13
quote:
Originally posted by russell

UPDATE	YourTable
SET version = left(version, Abs(charindex('.', version+'.')-1)) + '.x'





No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

cnbhold
Starting Member

43 Posts

Posted - 2010-07-30 : 14:02:53
Thanks worked! Thanks Russell and Webfred for all your help.

Angel
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-07-30 : 14:08:06
welcome


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -