[thelist] SQL Question - Drop the last charector of a string

Casey Crookston caseyc at IntelliSoftmn.com
Mon Aug 7 10:52:13 CDT 2006


Jason,

Okay.  We're on the right track here.  Thanks for your help.

SELECT * FROM temp_headings 

returns these rows (among many other):


Main_heading	sub_heading
----------------------------------------
Appliances		Major-Used-	
Appliances		Major-Parts & Supplies-	
Appliances		Major-New-	
Appliances		Major-Service & Repair-	

But this query:

SELECT main_heading,
REPLACE(sub_heading,right(sub_heading,1),'') AS sub_heading
FROM temp_headings

Returns the above rows as this:

Main_heading	sub_heading
----------------------------------------
Appliances		MajorUsed	
Appliances		MajorParts & Supplies	
Appliances		MajorNew	
Appliances		MajorService & Repair

So it's not just replacing the last character, it' replacing all
instances of the last character.  :-(  

As a reminder, this is what we need:

Main_heading	sub_heading
----------------------------------------
Appliances		Major-Used
Appliances		Major-Parts & Supplies
Appliances		Major-New
Appliances		Major-Service & Repair

For now let's forget about writing to the other table and just focus on
the correct SELECT statement.  I'll keep playing and trying.  And if
anyone else comes up with something, please do share!!!

Casey






More information about the thelist mailing list