sqlHere.com beta
  • Published
    Library of Sql Snippets for Microsoft SQL Server, Oracle systems.
  • Replace char at position
    DECLARE @test INT
    SET @test= 3 --char number from left in string to replace

    DECLARE @newValue AS CHAR(1)
    SET @newValue = 'X' --new value for replaced text

    DECLARE @inputText AS VARCHAR(10)
    SET @inputText = 'ababababab'

    SELECT CAST(SUBSTRING(@inputText,0,@test) AS VARCHAR) +
    @newValue + CAST(SUBSTRING(@inputText,@test+1,LEN(@inputText) - @test) AS VARCHAR)

    --RESULT 'abXbababab'
    tags:
©2007-2008 Marcin Kotynia contact & feedback, report bug | About Page generation Time:0.296875