views:

25

answers:

1

Hi All,

I want to create a stored procedure which will do matching of two tables. My requirement is to match two tables based on the columns user passes as an input.

Syntax: CREATE PROCEDURE reconcile.matchTables(IN TAB1 VARCHAR(25), IN TAB1 VARCHAR(25), IN COLS1 VARCHAR(250) , IN COLS2 VARCHAR(250))

EX: matchTables('table1', 'table2', 'col1#col2#col3#col4' , 'col2#col13#col1#col8')

Now the stored procedure should form the where clause like the following

table1.col1 = table2.col2 and table1.col2 = table2.col13 and table1.col3 = table2.col1 and table1.col4 = table2.col8

I am not good in stored procedures. please help me on creating the procedure.

Thanks,

Anil Kumar.C

A: 

SUBSTRING_INDEX(str,delim,count)

Returns the substring from string str before count occurrences of the delimiter delim. If count is positive, everything to the left of the final delimiter (counting from the left) is returned. If count is negative, everything to the right of the final delimiter (counting from the right) is returned. SUBSTRING_INDEX() performs a case-sensitive match when searching for delim.

mysql> SELECT SUBSTRING_INDEX('www.mysql.com', '.', 2);
        -> 'www.mysql'
mysql> SELECT SUBSTRING_INDEX('www.mysql.com', '.', -2);
        -> 'mysql.com'

This function is multi-byte safe.

Svisstack