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
 Removing number from data

Author  Topic 

Rayman
Starting Member

39 Posts

Posted - 2010-10-13 : 14:11:01
I have a column with the information as follows:
Table: john
Column: database_name

Database_name
database 143
database 2
database 3
database number 1

I am trying to create a script to produce just the number in order

such as this example:

database number
1
2
3
43

My approach was to look at the string and print the interger. Do not seem to find a correct function or command to perform this feat.
Any help would be appreciated. Thank you,

Terry Lynn King

Sachin.Nand

2937 Posts

Posted - 2010-10-13 : 14:15:28
Should it be 43 or 143 in the o/p ?

PBUH

Go to Top of Page

Rayman
Starting Member

39 Posts

Posted - 2010-10-13 : 14:16:36
It should be 43

quote:
Originally posted by Sachin.Nand

Should it be 43 or 143 in the o/p ?

PBUH





Terry Lynn King
Go to Top of Page

Sachin.Nand

2937 Posts

Posted - 2010-10-13 : 14:32:23
But ur data has value 143

Table: john
Column: database_name

Database_name
database 143
database 2
database 3
database number 1




PBUH

Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2010-10-13 : 14:34:42
[code]select
*,
DB_Num =convert(int,reverse(substring(reverse(DB),1,charindex(' ',reverse(DB))-1)))

from
(
select DB = 'database 1' union all
select DB = 'database 143' union all
select DB = 'database 44'
) b
order by
DB_Num[/code]
Results:
[code]DB DB_Num
------------ -----------
database 1 1
database 44 44
database 143 143 [/code]

CODO ERGO SUM
Go to Top of Page

Rayman
Starting Member

39 Posts

Posted - 2010-10-13 : 14:53:11
the desire output I am trying to produce is this:

database number
1
2
3
43

I am trying to look at the data and then produce the numbers in order

Terry Lynn King
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-10-13 : 15:36:42
what is the rule that makes 143 to 43?
looks senseless without explanation.


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

- Advertisement -