我写的存储过程要从数据库取出大量的字段,这些字段可能是null的,那么在c#代码中要对每个字段值进行判断。这样及其麻烦。
但如果值为空字符串就不必判断,要在表中存储空字符串可以直接把原来的值删除。但怎么设置字段默认值为空字符串呢?

解决方案 »

  1.   

    测试看看declare @table table(id int identity(1,1),pid int not null,code nvarchar(10) null,name nvarchar(20) default '')
    insert into @table (pid,code,[name]) values (0,'C01',null)
    insert into @table (pid,code) values (0,null)
    insert into @table (pid) values (0)
    select * from @table
      

  2.   

    在存储过程中用isnull函数也是可以的吧.
    select id,pid,isnull(code,'') as code,isnull([name],'') as [name] from @table
      

  3.   

    如果你使用的是ORACLE数据库,那么你可以使用nvl函数
    select nvl(a.xxx,'') from tablename
    或使用decode
    select decode(a.xxx,null,'',a.xxx) from tablename