sqlserver存储过程判断,所插入数值是否为空如果为空就跳过不插入,否则不为空就插入当前这条数据!求存储过程怎么写呀?跪求呀...这是我的数据库,求帮我写一个存储过程吧,我会重谢的!sqlserver存储数据库数据

解决方案 »

  1.   

    if null
    do nothing
    else
    insert。
      

  2.   

    你有那么多列,到底你要判断哪列不为空?还是所有列不为空?还有CreateDate不是创建日期吗?为何用数据类型varchar(80),而不是用datetime类型呢?
      

  3.   

    我只需要判断ContentText这个字段就行了
      

  4.   

    我只需要判断往ContentText这个字段里插入值时间值是否为空,如果值为空就跳过不插入(保证ContentText这个字段里面不能出现空值null),如果不为空则插入
      

  5.   

    直接表设置ContentText不能为空不就搞定了
      

  6.   


    这里有空值,我想做到在插入的时候,如果插入ContentText这条字段的值为空的,就直接把这一条所有的数据都给舍弃了不插入,否则的就插入,求存储过程呀
      

  7.   

    为什么不在C#这一层做呢,把ContentText为空的记录去掉,然后再插入数据库。
      

  8.   

    我代码是这么写的 string b = html.GetHTML("http://ent.qq.com" + href[count].Groups[0].Value, "gb2312");
                        System.Text.RegularExpressions.MatchCollection aa = quanwen.Matches(b);
                        foreach (Match k in aa)
                        {
                            if (k.ToString() != ""&&k.ToString().Length>150)
                            {
                                n.ContentText1 = (k.ToString());
                            }
                            else
                            {
                                break;
                            }
                        }
    如果 if (k.ToString() != ""&&k.ToString().Length>150)就插入数据,否则就是为空了,但是为空了怎么样才能跳出不插入呢我写了break也不行
      

  9.   

    这跟存储过程没什么关系吧  就是一个判断if(isemptyornull(xxx))
    {
      insert into ...
    }
      

  10.   

    你的后面应该还有代码吧  你写的break是跳出循环  后面的代码一样执行
      

  11.   

    if(isemptyornull(xxx))
    {
      insert into ...
    }这个是什么意思呢?可以吗
      

  12.   


    if  ( @ContentText is not null) AND (@ContentText <> '')
    insert  .....
      

  13.   

    create procedure  p_microblogging
    ..........
    @ContentText text
    ...........
    asif  ( @ContentText is not null) AND (@ContentText <> '')
    insert into microblogging(.....,ContentText) values(....,@ContentText)
      

  14.   

    我按照你的这样写了[url=http://]可是一执行就报错了
      

  15.   

    if(@ContentText is not null AND @ContentText <> '')
     begin
       insert into microblogging......
     end
      

  16.   

    引用 20 楼 lyc1992 的回复:
    我按照你的这样写了[url=http://]可是一执行就报错了
      

  17.   

    哦,看一下insert into 前后是否需要 begin insert into end 包围起来.
      

  18.   

    写个简单的你参考下,直接在后面加where就可以了CREATE TABLE TB(
    id INT,
    NAME VARCHAR(50)
    )
    goalter PROCEDURE p_test(
    @id INT,
    @name VARCHAR(50)
    )
    as
    INSERT TB(id,name) SELECT @id,@name 
    WHERE @name is NOT NULLEXEC p_test 1,NULLEXEC p_test 1,'aaa'SELECT * FROM TB
    DROP PROCEDURE p_test
    DROP TABLE TB
      

  19.   

    你的@ContentText参数在C#中没有提供或值为null