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)
 How SQL remove character?

Author  Topic 

wkm1925
Posting Yak Master

207 Posts

Posted - 2010-02-06 : 11:58:28
My table and rows as follow,

t1
PriceGroup
--------------
SERM
SPORE2RM
SPORESG$
WAHRM
SPORESUNRM
sporecnySG$

As you can see, there's 2 character at the end of the word. The character is RM and SG$.

How to remove that character? So, my resultset as follow,
t1
PriceGroup
--------------
SE
SPORE2
SPORE
WAH
SPORESUN
sporecny

Need help

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-06 : 12:04:14
[code]UPDATE t1
SET PriceGroup=LEFT(PriceGroup,LEN(PriceGroup)-2)
WHERE PATINDEX('%RM',Pricegroup) > 0

UPDATE t1
SET PriceGroup=LEFT(PriceGroup,LEN(PriceGroup)-3)
WHERE PATINDEX('%SG$',Pricegroup) > 0
[/code]
Go to Top of Page

wkm1925
Posting Yak Master

207 Posts

Posted - 2010-02-06 : 12:09:04
tq sir
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-06 : 12:10:00
welcome
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2010-02-06 : 17:28:16
@Visakh: I'm curious why PATINDEX rather than LIKE?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-07 : 10:31:10
quote:
Originally posted by Kristen

@Visakh: I'm curious why PATINDEX rather than LIKE?


you can use LIKE also. just used PATINDEX as it was a pattern search
Go to Top of Page
   

- Advertisement -