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.
Author |
Topic |
SQLBoy14
Yak Posting Veteran
70 Posts |
Posted - 2014-11-25 : 21:26:22
|
Anyone knows how do I do the sql string function:from: 222335650115ABC (Varchar data type)To: 222-33565-0115-ABCThank youSQLBoy |
|
MuralikrishnaVeera
Posting Yak Master
129 Posts |
Posted - 2014-11-26 : 00:54:50
|
You can play with PATINDEXDECLARE @var Varchar(max)='222335650115ABC'SELECT SUBSTRING(@var,0,PATINDEX('%[a-z]%',@var))+'-'+SUBSTRING(@var,PATINDEX('%[a-z]%',@var),LEN(@var))---------------Murali KrishnaYou live only once ..If you do it right once is enough....... |
|
|
SQLBoy14
Yak Posting Veteran
70 Posts |
Posted - 2014-11-26 : 08:51:14
|
Hello Murali, the output is only 222335650115-ABC. What I am trying to output is 222-33565-0115-ABC. Thanks!SQLBoy |
|
|
Muj9
Yak Posting Veteran
75 Posts |
Posted - 2014-11-26 : 08:58:03
|
DECLARE @var Varchar(20)='222335650115ABC'select left(@var,3)+'-'+SUBSTRING(@var,4,5)+'-'+SUBSTRING(@var,9,4)+'-'+right(@var,3) |
|
|
cvipin
Yak Posting Veteran
51 Posts |
Posted - 2014-12-02 : 19:42:24
|
DECLARE @Data Varchar(20)='222335650115ABC'SELECT STUFF(STUFF(STUFF(@Data, 4, 0, '-'), 10, 0, '-'), 15, 0, '-') |
|
|
|
|
|
|
|