Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Argument data type varchar is invalid for argument 2 of substring function

I’m trying to put 2x’-‘ in phone number and I’m getting the following error

Argument data type varchar is invalid for argument 2 of substring
function.

I’m working on Tsql. I also try ‘mid’ function – no results. I need a result like ‘123-456-789’.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

declare @tel nvarchar(20) = 123456789
set @tel = (select left (@tel, '3'))+'-'+(select substring (@tel, '4','3'))+'-'+(select right (@tel, '3'))
select @tel

>Solution :

Your Query modified as below

declare @tel nvarchar(20) = '123456789'
set @tel = (select left (@tel, 3))+'-'+(select substring (@tel, 4,3))+'-'+(select right (@tel, 3))
select @tel

can Re write as below

declare @tel nvarchar(20) = '123456789'
set @tel = left (@tel, 3)+'-'+substring (@tel, 4,3)+'-'+ right (@tel, 3)
select @tel
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading