We help IT Professionals succeed at work.

Replace Characters SQL

garethtnash
garethtnash used Ask the Experts™
on
I have a SQL select statement, which currently includes ;

'###' + RIGHT(L.Password,2) AS Password,

What I was actually hoping to do, is count the number of charcters in the password and for whatever this amounts to return that number (minus 2) hashes followed by the last two characters of the password...

Appreciate any thoughts / suggestions.

Many thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Aaron ShiloChief Database Architect

Commented:
hi

select LEN(@pInput) - LEN(REPLACE(@pInput, @pSearchChar, ''))

Open in new window

Author

Commented:
So -

LEN(L.Password) - LEN(REPLACE(L.Password, 3, '#'))+ RIGHT(L.Password,2) AS Password,

?

I get -

Msg 245, Level 16, State 1, Line 3
Conversion failed when converting the nvarchar value 's1' to data type int.

Thanks
I think you need this


Replace(L.Password,Substring(L.Password ,1,Len(L.Password)-2),REPLICATE('#',Len(L.Password)-2) )

Author

Commented:
Superb, thank you