ASP.NET - select query

Asked By rashmi r on 18-Apr-12 06:36 AM
hi friends,

how to this query in mysql,

sql server query:

select ('+1-' +left( src , 3 )+ '-' + substring( src , 4 , 3 )+ '-' + substring ( src , 7 , 4 )) as src from mytable



please give the  solution,

its urgent.


thanks.
kalpana aparnathi replied to rashmi r on 18-Apr-12 06:40 AM
hi,

Please check it out like this.

SELECT SUBSTRING('1035442030',1,3) + '-' + SUBSTRING('1035442030',4,3) + '-' + SUBSTRING('1035442030',7,4)
 
Regards,
rashmi r replied to kalpana aparnathi on 18-Apr-12 06:57 AM
its not working,,

Now i inserted like this

7032442030

but

+1-703-244-2030


sql server query:

select ('+1-' +left( src , 3 )+ '-' + substring( src , 4 , 3 )+ '-' + substring ( src , 7 , 4 )) as src from mytable

please give the query  in mysql
Web Star replied to rashmi r on 18-Apr-12 07:22 AM
left ans substring also work in mysql so that query should give you correct result

select '+1-' +left( src , 3 )+ '-' + substring( src , 4 , 3 )+ '-' + substring ( src , 7 , 4 ) as src from mytable  

Only make sure in your table the column src should have 10 digit value than it will work
if this is not works let me know the error.
Chintan Vaghela replied to rashmi r on 18-Apr-12 08:52 AM

Hello,

 

Use Concat function as following way

 

select CONCAT('+1-' ,left( src , 3 ), '-', substring( src , 4 , 3 ), '-' , substring ( src , 7 , 4 )) as src from mytable 

 

 

Hope this helpful!

Thanks