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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Split

Author  Topic 

haroon2k9
Constraint Violating Yak Guru

328 Posts

Posted - 2010-10-29 : 07:48:55
hi,

i have a column name as "Helpdeskid" and value as

Helpdeskid

HD-001
HD-002
HD-003
---
HD-1000
HD-1000000
HD-10000000
--------------

i just waantto split and reslut must be
1
2
3
4
5
6
...
1000
100000
1000000
100000000
pl help me..

notmyrealname

98 Posts

Posted - 2010-10-29 : 08:07:19
CAST(SUBSTRING([Helpdeskid], CHARINDEX('-', [Helpdeskid]) + 1, LEN([Helpdeskid])) AS int)

Search help for SQL String Functions. You will find lots of useful functions that help with this kind of stuff.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-10-29 : 08:11:50
select convert(int,replace(Helpdeskid,'HD-',''))


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

vaibhavktiwari83
Aged Yak Warrior

843 Posts

Posted - 2010-10-29 : 08:29:00
select convert(int,RIGHT(helpdeskid, LEN(helpdeskid) - 3))

Vaibhav T

To walk FAST walk ALONE
To walk FAR walk TOGETHER
Go to Top of Page

notmyrealname

98 Posts

Posted - 2010-10-29 : 08:30:51
quote:
Originally posted by webfred

select convert(int,replace(Helpdeskid,'HD-',''))


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



Why didn't i think of that! Nice!
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-11-01 : 07:28:20
or

select parsename(replace(Helpdeskid ,'-','.'),1)*1 from table

Madhivanan

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

- Advertisement -