SQL MID() and SQL-Server SUBSTRING() FUNCTION

SQL MID() and SQL-Server SUBSTRING() Function

MID() - The MID() function is used to return exact text from given text field.
The syntax of MID() for SQL :

 

In SQL Server we use SUBSTRING() function.
The syntax of SUBSTRING() in SQL Server :

sql mid and substring

Sql MID() and SQL server SUBSTRING() function

Here, we understand MID() and SUBSTRING() function with an example.
We have SQL Table StudentMst with below column.

SELECT * FROM StudentMst

ID Name City Pincode Mobile
1 Meera Bombay 380022 7874555555
2 Rahul Surat 352200 7874444444
3 Jayesh Ahmedabad 352200 7874333333
4 Dhvanish Bombay 380022 7874111111
5 Reena Baroda 352222 7874666666
6 Veera Baroda 352222 7874121212

 

SELECT MID(name, 1, 3) as  Name, MID(city, 1, 3) as  City FROM StudentMst

Name City
Mee omb
Rah ura
Jay hme
Dhv omb
Ree aro
Vee aro

 

SELECT SUBSTRING(name, 1, 3) as  Name, SUBSTRING(city, 1, 3) as  City FROM StudentMst

Name City
Mee omb
Rah ura
Jay hme
Dhv omb
Ree aro
Vee aro

Leave a Reply

Your email address will not be published. Required fields are marked *

6 + 3 =


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">