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
 How to remove a portion of a column data?

Author  Topic 

AdamWest
Constraint Violating Yak Guru

360 Posts

Posted - 2011-02-22 : 16:24:57
HI I Have many entries that have this 'HK' as a kind of prefix.
while i have nothing against HK, the sales person would like this HK removed.
the name of this column is categoryname

HK-Dietary
HK-Jan

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2011-02-22 : 16:42:14
http://msdn.microsoft.com/en-us/library/ms181984.aspx
Go to Top of Page

MIK_2008
Master Smack Fu Yak Hacker

1054 Posts

Posted - 2011-02-23 : 00:10:44
@lamprey

@adam, right, replace
Go to Top of Page

mmarovic
Aged Yak Warrior

518 Posts

Posted - 2011-02-23 : 03:31:37
substring, patindex?

Mirko

My blog: http://mirko-marovic-eng.blogspot.com/
Go to Top of Page

mmarovic
Aged Yak Warrior

518 Posts

Posted - 2011-02-23 : 04:56:43
Actually, substring is enough.

case
when categoryname like 'HK-%' then substring(...)
else categoryName
end


Mirko

My blog: http://mirko-marovic-eng.blogspot.com/
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-02-23 : 05:38:16
-- making testdata
declare @test table (ttt varchar(255))
insert @test
select 'HK-123' union all
select 'HP-456' union all
select 'HK4588'

-- solution
select stuff(ttt,1,3,'') as result from @test where ttt like 'HK-%'


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

- Advertisement -