May 26, 2010

SQL Substring Function

by Matnet @ 4:56 pm in WWW

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 :

Select table1.userid, table1.name, table2,password from table1, table2 WHERE table1.userid = SUBSTR(table2.userid, 2)





Comments
* Name


* Email Address (will not be published)


Site



*Image Validation (?)

Comments

HTML: NO


:: Shout Me ::



:: About Me ::



They call me : Yachiru
Name : Yachiru Kusajishi
Birthday : February 12
Working Field : Shinigami lieutenant - 11th Division
E-mail : matnet80 [at] yahoo [dot] com


:: Calendar ::

February 2012
S M T W T F S
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29