yandex
loader

please wait

  • Arminder Gill Mar-12-2019 08:00:11 AM ( 1 week ago )

    How Can I separate characters and number from a word using SQL Server query?

    Example word: AB12C34DE

    The Output is like:

    col1
    -----    
    ABCDE
    
    col2
    -----
    1234
  • Kamal Thakur Mar-12-2019 08:02:06 AM ( 1 week ago )

    Please try this.

    DECLARE @Numstring varchar(100)
    SET @Numstring = 'AB12C34DE'
    WHILE PATINDEX('%[^0-9]%',@Numstring) <> 0.
    SET @Numstring = STUFF(@Numstring,PATINDEX('%[^0-9]%',@Numstring),1,'')
    SELECT @Numstring As Number
    
    DECLARE @Charstring varchar(100)
    SET @Charstring = 'AB12C34DE'
    WHILE PATINDEX('%[^A-Z]%',@Charstring) <> 0.
    SET @Charstring = STUFF(@Charstring,PATINDEX('%[^A-Z]%',@Charstring),1,'')
    SELECT @Charstring As Character

Please login

Similar Discussion

Recommended For You