Click to See Complete Forum and Search --> : How to truncate String column using sql query.


anilreddy76
09-17-2007, 04:12 PM
Hi,

I'm having one location table where the values of location are returned as KC_KansasCity,CHAR_Charlotte,PEW_Pewauke etc,I want to truncate the characters before underscore and also underscore while inserting the data into table.

Can anybody advise me on how to do this..

Thanks,
Anil

bubbisthedog
09-18-2007, 01:04 PM
Don't know what product you're using (MySQL, SQL Server, etc.), but I'd suggest researching substr() and instr().

mattyblah
09-18-2007, 01:39 PM
the equivalent functions bubb suggested are substring and charindex/patindex for sql server.

bubbisthedog
09-18-2007, 03:01 PM
Thanks, matty. :)