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 2012 Forums
 Transact-SQL (2012)
 Remove character from string

Author  Topic 

gjack0519
Starting Member

7 Posts

Posted - 2014-06-13 : 16:59:29
I am trying to remove the 12th character from a nvarchar field.

This number
057381890100005 would read
05738189010005 after the removal.
All values have a length of 16 and the 12th character can be any value of 0-9.

Any Ideas?
Thanks

GJ

robvolk
Most Valuable Yak

15732 Posts

Posted - 2014-06-13 : 17:04:18
SELECT STUFF('057381890100005', 12, 1, '')

As a query:

SELECT STUFF(myColumn, 12, 1, '') FROM myTable
Go to Top of Page

gjack0519
Starting Member

7 Posts

Posted - 2014-06-13 : 17:25:18
Perfect
I kept trying to use Substring and the len functions, but kept getting wrong results.

Thanks
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2014-06-13 : 18:16:29
SELECT LEFT(Col1, 11) + RIGHT(Col1, 4)
FROM dbo.Table1

SELECT SUBSTRING(Col1, 1, 11) + SUBSTRING(Col1, 13, 4)
FROM dbo.Table1



Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA
Go to Top of Page
   

- Advertisement -