have a try:declare @colname varchar(10) declare cur cursor for select c.name from syscolumns c ,sysobjects o where o.id=c.id and o.id=object_id('authors') declare @str varchar(100) select @str='''aaa''' open cur fetch next from cur into @colname begin exec('update authors set ' +@colname +' =isnull( ' +@colname+' ,'+@str+')') end while @@fetch_status=0 beginexec('update authors set ' +@colname +' =isnull( ' +@colname+' ,'+@str+')') fetch next from cur into @colname endclose cur deallocate cur
你可以写一段sql脚本,自动生成update语句即可。
default为‘’就好了。
declare cur cursor for
select c.name from syscolumns c ,sysobjects o where
o.id=c.id and o.id=object_id('authors')
declare @str varchar(100)
select @str='''aaa'''
open cur
fetch next from cur into @colname
begin
exec('update authors set ' +@colname +' =isnull( ' +@colname+' ,'+@str+')')
end
while @@fetch_status=0
beginexec('update authors set ' +@colname +' =isnull( ' +@colname+' ,'+@str+')')
fetch next from cur into @colname
endclose cur
deallocate cur
利用syscolumns 找到你要的列
利用SysTypes 找到你要的varchar类型
然后根据大力的方法解决就可以了.
其实不太麻烦!
谢谢大家,因为我在应用程序里有时需要删除一个值,删除之后就在SQL里成了<NULL>了,不过我现在根据大家的意见已经实现了所有字段的清空,感谢大家!