我应该如何把日期也写入表中呢?insert   into   table1(nid,date) 
SELECT isnull((select 流水号 = right('00'+rtrim(isnull(max(cast(nid as int)),0)+1),4),date    
from 
table1    
where datediff(day,date,getdate()) = 0),1) 
Server: Msg 120, Level 15, State 1, Line 5
The select list for the INSERT statement contains fewer items than the insert list. The number of SELECT values must match the number of INSERT columns.

解决方案 »

  1.   

    insert into table1(nid,date) 
    SELECT isnull(right('00'+rtrim(isnull(max(cast(nid as int)),0)+1),4),MAX(date)
    from table1 where datediff(day,date,getdate()) = 0
      

  2.   

    表中有两个fields
    你去查出一个field,肯定不行拉!
      

  3.   

    抱歉,更正一下:
    insert into table1(nid,date) 
    SELECT isnull(right('00'+rtrim(isnull(max(cast(nid as int)),0)+1),4),'0001'),MAX(date)
    from table1 where datediff(day,date,getdate()) = 0
      

  4.   

    按照hellowork(一两清风)的方法出现了这样的情况按照表中最大的日期能写入数据库,但是如果日期没有记录,写入的就是一个空值id nid date
    1  2   2007-06-15这时候能写入如果系统时间进入16日,但表中没有记录,写入的就是一个空值
      

  5.   


    MAX(date)
    改成
    isnull(MAX(date),getdate())
    试试.即如果为空则使用当前日期.