1. 程式人生 > >【資料庫SQL】SQL查詢和替換含有回車,空格,TAB,等

【資料庫SQL】SQL查詢和替換含有回車,空格,TAB,等

---如下是查詢語句 --查詢名稱有退格鍵 select * from t_bd_item_info  where charindex(char(8),item_name) > 0  go --查詢名稱有製表符tab  select * from t_bd_item_info  where charindex(char(9),item_name) > 0  go --查詢名稱有換行   select * from t_bd_item_info where charindex(char(10),item_name) > 0  go --查詢名稱有回車   select * from t_bd_item_info where charindex(char(13),item_name) > 0  go --查詢名稱的空格(前空格、後空格、所有空格) select * from t_bd_item_info where isnull(charindex(' ',item_name),0) > 0    go --查詢名稱的單引號  select * from t_bd_item_info where charindex(char(39),item_name) > 0  go --查詢名稱的雙單引號  select * from t_bd_item_info where charindex(char(34),item_name) > 0  go --處理名稱有退格鍵 update t_bd_item_info set item_name = replace(item_name,char(8),'')  where charindex(char(9),item_name) > 0  go --處理名稱有製表符tab  update t_bd_item_info set item_name = replace(item_name,char(9),'')  where charindex(char(9),item_name) > 0  go --處理名稱有換行   update t_bd_item_info set item_name = replace(item_name,char(10),'')  where charindex(char(10),item_name) > 0  go --處理名稱有回車   update t_bd_item_info set item_name = replace(item_name,char(13),'')  where charindex(char(13),item_name) > 0  go --處理名稱的空格(前空格、後空格、所有空格) update t_bd_item_info set item_name = replace(rtrim(ltrim(item_name)),' ','')   where isnull(charindex(' ',item_name),0) > 0    go --處理名稱的單引號  update t_bd_item_info set item_name = replace(item_name,char(39),'')  where charindex(char(39),item_name) > 0  go --處理名稱的雙單引號  update t_bd_item_info set item_name = replace(item_name,char(34),'')  where charindex(char(34),item_name) > 0  go