|
|
sql server中格式化表中的数据 |
|
|
作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站 |
在数据库开发中,由于用户录入信息的随意性,可能产生表内字符串类型的 数据两端存有空格,或大小写不一致等现象,给以后数据应用过程中造成不必要的麻烦。这里简单使用了一个存储过程来解决这些问题。
/* 整理系统数据*/ CREATE PROCEDURE pro_ClearupData as --第一部分 整理字符串类型的数据 去除两端的空格 declare @tableName varchar(50) --表名 declare @columnName varchar(50) --列名 declare cur_find cursor for select so.name,sc.name from syscolumns sc, sysobjects so, systypes st where so.name <> 'dtproperties' and st.xtype=sc.xtype and st.name='varchar' and sc.id=so.id and so.xtype='u' --查找包含varchar类型字段的所有用户表 open cur_find fetch next from cur_find into @tableName,@columnName while @@fetch_status=0 begin --去掉字段的两端空格 exec('update '+@tableName+' set '+@columnName+'=ltrim(rtrim('+@columnName+'))') fetch next from cur_find into @tableName,@columnName end close cur_find deallocate cur_find GO

|
|
相关文章:相关软件: |
|