我到底错哪了? 数据库高手请进!
联合查询语句没错,我已经能够查询.但我想把查询保存到表DJ3时,报错!搞不懂!
语句如下:
sql = "insert into dj3(bzw,xtbh ,xm , gxfl ,fsdx,sqsy ,sqje, djwp ,fssj ,sqsj ) select bzw,xtbh ,xm , gxfl ,fsdx,sqsy ,sqje, djwp ,fssj ,sqsj from sqdjb1 where xm = ' " + Text1.Text + " ' or (fssj between # " & Format(DTPicker1.Value, "yyyy-M-dd ") & " # and # " & Format(DTPicker2.Value, "yyyy-M-dd ") & "# ) union all select * from sqdjb2 where xm = ' " + Text1.Text + " ' or (fssj between # " & Format(DTPicker1.Value, "yyyy-M-dd ") & " # and # " & Format(DTPicker2.Value, "yyyy-M-dd ") & "# "
cnn.Execute sql
[解决办法]
ssql= "insert into dj3(bzw,xtbh ,xm , gxfl ,fsdx,sqsy ,sqje, djwp ,fssj ,sqsj ) "
ssql=ssql & vbcrlf & "select bzw,xtbh ,xm , gxfl ,fsdx,sqsy ,sqje, djwp ,fssj ,sqsj "
ssql=ssql & vbcrlf & "from sqdjb1 where xm = ' "& text1.text & " ' or (fssj between '1999-02-02 ' and '1999-02-02 ') "
ssql=ssql & vbcrlf & "union all "
ssql=ssql & vbcrlf & "select * "
ssql=ssql & vbcrlf & "from sqdjb2 where xm = ' "& text1.text & " ' or (fssj between '1999-2-01 ' and '1999-02-02 ') "
--表sqdjb2最好写全字段. 写出SQL语句后再加条件.