SQL Substring Function

The Substring function in SQL is used to grab a portion of the stored data. This function is called differently for the different databases:

* MySQL: SUBSTR(), SUBSTRING()
* Oracle: SUBSTR()
* SQL Server: SUBSTRING()

Example :

Let say u have 2 table from old db.

Table1
userid
name

Table2
userid
password

userid in table1 and userid in table2 is identical but userid in table 1 start with letters T and userid in table 2 is not start with T

for example.

Table1
userid name
1 itik
2 ayam
3 kambing
4 bangau

Table2
userid password
T1 ******
T2 ******
T3 ******
T4 ******

so we need to use sql substring function to erase the T to make it identical.

The query :

[quote]Select table1.userid, table1.name, table2,password from table1, table2 WHERE table1.userid = SUBSTR(table2.userid, 2)[/quote]

This article was written by matn0t.