Thread: Need help with db procedure

Need help with db procedure

From
AGRE Enterprises
Date:
I am trying to work out whether what I want to do is even possible. If it
is, how does one do it.

I wish to insert a row into table x. One of the columns has been a varchar
but examining the data has shown that of the 350,000 rows, there are only
18,000 unique values for the column.  What I want to do is to put those
18,000 values in another table and replace the column in my table x by a
key into the new table.

I want the new insert to look something like this.

insert into table x values (
'aaa','bbb', key_of( "abcdefghijkl" ) );

I want the key_of function to either return the appropriate key if the
parameter is already in the other table, or create a new row and return
its key if it isn't.

I am struggling to work out how to do this as sql doesn't seem to support
an 'if'.

Any help appreciated.

PS: I am not currently subscribed to the list so can you cc: or reply
to me directly. Thanks.
--
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Glen Eustace, on behalf of
GodZone Internet Services, a division of AGRE Enterprises Limited
176 Te Awe Awe Street, Palmerston North, New Zealand
Ph: +64 6 356 2562, Fax: +64 6 357 0271
http://www.godzone.net.nz, EMail: agree@godzone.net.nz, ICQ: 10397208
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=