In database development, due to the random of user entry information, it is possible to generate a string type
There are spaces in both ends of the data, or cases are inconsistent, etc., resulting in unnecessary trouble during data application. A stored procedure is simply used here to solve these problems.
/ * Solid system data * /
Create Procedure Pro_Clearupdata
AS
- The first partial finishing string type data removes spaces in both ends
Declare @tablename VARCHAR (50) - Table name
Declare @columnname varchar (50) - column name
Declare cur_find cursor for select sol.name, sc.name
From syscolumns sc, sysobjects so, systempes st
Where sol.name <> DTPROPERTIES '
And st.xtype = sc.XTYPE
And st.name = 'varchar'
And sc.id = SO.ID
And soli = 'u'
- Find all user tables that contain VARCHAR type fields
Open cur_find
Fetch next from cur_find INTO @ TableName, @ ColumnName
While @@ fetch_status = 0
Begin
- Remove the space between the fields
Exec ('Update
' @ TableName ' Set
' @ columnname ' = LTRIM (RTRIM (' @ ColumnName ))))
Fetch next from cur_find INTO @ TableName, @ ColumnName
end
Close Cur_Find
Deallocate Cur_Find
Go