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
 Code

Author  Topic 

dr223
Constraint Violating Yak Guru

444 Posts

Posted - 2010-06-24 : 05:19:47
Hi,

I have a set of values as shown below;

025_XX50
3745_YX40
34_YY10

_XX50, _YX40, _YY10 as noticed are 5 characters, and they will always be in that format.

What I want to do is have a query to read any other characters before the 5 characters, in this scenario 025, 3745, 34.

Any help please, thanks

karthik_padbanaban
Constraint Violating Yak Guru

263 Posts

Posted - 2010-06-24 : 05:27:51
declare @t table (a varchar(100))
insert into @t values ('025_XX50')
insert into @t values ('3745_YX40')
insert into @t values ('34_YY10')

select substring(a,1,charindex('_',a)-1) from @t

or

select substring(a,1,len(a)-5) from @t


Karthik
http://karthik4identity.blogspot.com/
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-06-24 : 05:30:13
select left(col, len(col) - 5)


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -