



CREATE PROCEDURE DBO.Delete_Leading_Trailing_Chars AS
SET NOCOUNT ON
/*
  Created by Kent Johansen 20050810

*/

DECLARE @Str VARCHAR(50)
DECLARE @AddNo INT

DECLARE db_cur CURSOR FOR
  SELECT LastName, AddressNumber
  FROM ReservationAddress WITH (NOLOCK)
  WHERE LTRIM(LastName) <> ''
  AND (CHARINDEX('''', LastName) = 1 OR CHARINDEX('''', LastName) = LEN(LastName))
OPEN db_cur 
	   
FETCH NEXT FROM db_cur INTO @Str, @AddNo

WHILE @@fetch_status = 0 
BEGIN
  IF LEFT(@Str,1) = ''''  -- Leading '
    SET @Str = STUFF(@Str,1,1,'')
	
  IF RIGHT(@Str,1) = ''''  -- Trailing '
    SET @Str = STUFF(@Str,Len(@Str),1,'')
	
  UPDATE ReservationAddress SET LastName = @Str WHERE AddressNumber = @AddNo
  FETCH NEXT FROM db_cur INTO @Str, @AddNo
END

DEALLOCATE db_cur

