我应该如何把日期也写入表中呢?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.
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.
SELECT isnull(right('00'+rtrim(isnull(max(cast(nid as int)),0)+1),4),MAX(date)
from table1 where datediff(day,date,getdate()) = 0
你去查出一个field,肯定不行拉!
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
1 2 2007-06-15这时候能写入如果系统时间进入16日,但表中没有记录,写入的就是一个空值
MAX(date)
改成
isnull(MAX(date),getdate())
试试.即如果为空则使用当前日期.