SQ查询分析器报错,但我想用一条Update同时修改两个字段的值,
不知能不能做到,如能请提示,谢谢!
14 个解决方案
#1
Update Tb_A set Fa = 1,Fb = 2, ....
#2
Update Tb
Set fa=値1,fb=値2
Where 条件
Set fa=値1,fb=値2
Where 条件
#3
但是我要更新的查询后面很长是从另一表中统计出来的(如下面)
Update tb_xz_salary set NoworkHours=(select isnull(sum(tb_kq_nowork.NoWorkHours),0) from tb_kq_nowork where isnull(tb_kq_nowork.checker,'')<>'' and tb_kq_nowork.Emp_id=tb_xz_salary.Emp_id and tb_kq_nowork.Noworkdate>='2004-02-01' and tb_kq_nowork.Noworkdate<'2004-03-01' group by tb_kq_nowork.Emp_id) where tb_xz_salary._year=2004 and tb_xz_salary._month=2
而第二条也是从刚才的表中统计出来的而且条件也一样,我不想统计,更新两次
Update tb_xz_salary set NoworkPay=(select isnull(sum(tb_kq_nowork.Pay),0) from tb_kq_nowork where isnull(tb_kq_nowork.checker,'')<>'' and tb_kq_nowork.Emp_id=tb_xz_salary.Emp_id and tb_kq_nowork.Noworkdate>='2004-02-01' and tb_kq_nowork.Noworkdate<'2004-03-01' group by tb_kq_nowork.Emp_id) where tb_xz_salary._year=2004 and tb_xz_salary._month=2
将两个字段分别对应两个(统计)查询语句就可以通过,如果我想两个字段对应一条(统计)查询的语句行不行?如果行请示例。
Update tb_xz_salary set NoworkHours=(select isnull(sum(tb_kq_nowork.NoWorkHours),0) from tb_kq_nowork where isnull(tb_kq_nowork.checker,'')<>'' and tb_kq_nowork.Emp_id=tb_xz_salary.Emp_id and tb_kq_nowork.Noworkdate>='2004-02-01' and tb_kq_nowork.Noworkdate<'2004-03-01' group by tb_kq_nowork.Emp_id) where tb_xz_salary._year=2004 and tb_xz_salary._month=2
而第二条也是从刚才的表中统计出来的而且条件也一样,我不想统计,更新两次
Update tb_xz_salary set NoworkPay=(select isnull(sum(tb_kq_nowork.Pay),0) from tb_kq_nowork where isnull(tb_kq_nowork.checker,'')<>'' and tb_kq_nowork.Emp_id=tb_xz_salary.Emp_id and tb_kq_nowork.Noworkdate>='2004-02-01' and tb_kq_nowork.Noworkdate<'2004-03-01' group by tb_kq_nowork.Emp_id) where tb_xz_salary._year=2004 and tb_xz_salary._month=2
将两个字段分别对应两个(统计)查询语句就可以通过,如果我想两个字段对应一条(统计)查询的语句行不行?如果行请示例。
#4
应该是可以的吧,我手头没有access
strSQLSUB1:='你的子查询1',strSQLSUB2:='你的子查询2'
strSQL:='update tb_xz_salary set NoworkHours='+strsqlsub1+' ,NoworkPay='+strsubsql2
然后提交这条sql试试
strSQLSUB1:='你的子查询1',strSQLSUB2:='你的子查询2'
strSQL:='update tb_xz_salary set NoworkHours='+strsqlsub1+' ,NoworkPay='+strsubsql2
然后提交这条sql试试
#5
合在一起不就行了嘛~!
就想这样:
Update tb_xz_salary set NoworkHours=(select isnull(sum(tb_kq_nowork.NoWorkHours),0) from tb_kq_nowork where isnull(tb_kq_nowork.checker,'')<>'' and tb_kq_nowork.Emp_id=tb_xz_salary.Emp_id and tb_kq_nowork.Noworkdate>='2004-02-01' and tb_kq_nowork.Noworkdate<'2004-03-01' group by tb_kq_nowork.Emp_id) ,
NoworkPay=(select isnull(sum(tb_kq_nowork.Pay),0) from tb_kq_nowork where isnull(tb_kq_nowork.checker,'')<>'' and tb_kq_nowork.Emp_id=tb_xz_salary.Emp_id and tb_kq_nowork.Noworkdate>='2004-02-01' and tb_kq_nowork.Noworkdate<'2004-03-01' group by tb_kq_nowork.Emp_id)
where tb_xz_salary._year=2004 and tb_xz_salary._month=2
更新成像你这样的结果值我没有做过,但是我类似的update句子~!
就想这样:
Update tb_xz_salary set NoworkHours=(select isnull(sum(tb_kq_nowork.NoWorkHours),0) from tb_kq_nowork where isnull(tb_kq_nowork.checker,'')<>'' and tb_kq_nowork.Emp_id=tb_xz_salary.Emp_id and tb_kq_nowork.Noworkdate>='2004-02-01' and tb_kq_nowork.Noworkdate<'2004-03-01' group by tb_kq_nowork.Emp_id) ,
NoworkPay=(select isnull(sum(tb_kq_nowork.Pay),0) from tb_kq_nowork where isnull(tb_kq_nowork.checker,'')<>'' and tb_kq_nowork.Emp_id=tb_xz_salary.Emp_id and tb_kq_nowork.Noworkdate>='2004-02-01' and tb_kq_nowork.Noworkdate<'2004-03-01' group by tb_kq_nowork.Emp_id)
where tb_xz_salary._year=2004 and tb_xz_salary._month=2
更新成像你这样的结果值我没有做过,但是我类似的update句子~!
#6
补充一下,我没有做过这么长的结果值,真的太长了,呵呵~
合在一起做,问题不大,应该是可以的!
合在一起做,问题不大,应该是可以的!
#7
可以
#8
我也没有做过这么长的结果值,真的太长了!其实你可以把这个语句写得更加简单
点的,
点的,
#9
其实两个sum值是在一个表中取得的,我只想统计一次就搞定,但这的话还是要分两次,不是太没效力,有没有类似insert into的语句一次搞定多个字段...........
#10
Update 绝对没有问题!
Update A
set A.Col1= B.Col1,
A.Col2= B.Col2
from AAA A
join (select Sum(sls) Col1, Sum(ada)Col2 from SSS ) B on (????)
Update A
set A.Col1= B.Col1,
A.Col2= B.Col2
from AAA A
join (select Sum(sls) Col1, Sum(ada)Col2 from SSS ) B on (????)
#11
当然能了
#12
可以得
#13
Update tb1 set a.Col1= b.Col1,a.Col2= b.Col2
from tb1 as a ,(select id,Col1,Col2 from tb2 ) as b
where a.id=b.id
from tb1 as a ,(select id,Col1,Col2 from tb2 ) as b
where a.id=b.id
#14
能
#1
Update Tb_A set Fa = 1,Fb = 2, ....
#2
Update Tb
Set fa=値1,fb=値2
Where 条件
Set fa=値1,fb=値2
Where 条件
#3
但是我要更新的查询后面很长是从另一表中统计出来的(如下面)
Update tb_xz_salary set NoworkHours=(select isnull(sum(tb_kq_nowork.NoWorkHours),0) from tb_kq_nowork where isnull(tb_kq_nowork.checker,'')<>'' and tb_kq_nowork.Emp_id=tb_xz_salary.Emp_id and tb_kq_nowork.Noworkdate>='2004-02-01' and tb_kq_nowork.Noworkdate<'2004-03-01' group by tb_kq_nowork.Emp_id) where tb_xz_salary._year=2004 and tb_xz_salary._month=2
而第二条也是从刚才的表中统计出来的而且条件也一样,我不想统计,更新两次
Update tb_xz_salary set NoworkPay=(select isnull(sum(tb_kq_nowork.Pay),0) from tb_kq_nowork where isnull(tb_kq_nowork.checker,'')<>'' and tb_kq_nowork.Emp_id=tb_xz_salary.Emp_id and tb_kq_nowork.Noworkdate>='2004-02-01' and tb_kq_nowork.Noworkdate<'2004-03-01' group by tb_kq_nowork.Emp_id) where tb_xz_salary._year=2004 and tb_xz_salary._month=2
将两个字段分别对应两个(统计)查询语句就可以通过,如果我想两个字段对应一条(统计)查询的语句行不行?如果行请示例。
Update tb_xz_salary set NoworkHours=(select isnull(sum(tb_kq_nowork.NoWorkHours),0) from tb_kq_nowork where isnull(tb_kq_nowork.checker,'')<>'' and tb_kq_nowork.Emp_id=tb_xz_salary.Emp_id and tb_kq_nowork.Noworkdate>='2004-02-01' and tb_kq_nowork.Noworkdate<'2004-03-01' group by tb_kq_nowork.Emp_id) where tb_xz_salary._year=2004 and tb_xz_salary._month=2
而第二条也是从刚才的表中统计出来的而且条件也一样,我不想统计,更新两次
Update tb_xz_salary set NoworkPay=(select isnull(sum(tb_kq_nowork.Pay),0) from tb_kq_nowork where isnull(tb_kq_nowork.checker,'')<>'' and tb_kq_nowork.Emp_id=tb_xz_salary.Emp_id and tb_kq_nowork.Noworkdate>='2004-02-01' and tb_kq_nowork.Noworkdate<'2004-03-01' group by tb_kq_nowork.Emp_id) where tb_xz_salary._year=2004 and tb_xz_salary._month=2
将两个字段分别对应两个(统计)查询语句就可以通过,如果我想两个字段对应一条(统计)查询的语句行不行?如果行请示例。
#4
应该是可以的吧,我手头没有access
strSQLSUB1:='你的子查询1',strSQLSUB2:='你的子查询2'
strSQL:='update tb_xz_salary set NoworkHours='+strsqlsub1+' ,NoworkPay='+strsubsql2
然后提交这条sql试试
strSQLSUB1:='你的子查询1',strSQLSUB2:='你的子查询2'
strSQL:='update tb_xz_salary set NoworkHours='+strsqlsub1+' ,NoworkPay='+strsubsql2
然后提交这条sql试试
#5
合在一起不就行了嘛~!
就想这样:
Update tb_xz_salary set NoworkHours=(select isnull(sum(tb_kq_nowork.NoWorkHours),0) from tb_kq_nowork where isnull(tb_kq_nowork.checker,'')<>'' and tb_kq_nowork.Emp_id=tb_xz_salary.Emp_id and tb_kq_nowork.Noworkdate>='2004-02-01' and tb_kq_nowork.Noworkdate<'2004-03-01' group by tb_kq_nowork.Emp_id) ,
NoworkPay=(select isnull(sum(tb_kq_nowork.Pay),0) from tb_kq_nowork where isnull(tb_kq_nowork.checker,'')<>'' and tb_kq_nowork.Emp_id=tb_xz_salary.Emp_id and tb_kq_nowork.Noworkdate>='2004-02-01' and tb_kq_nowork.Noworkdate<'2004-03-01' group by tb_kq_nowork.Emp_id)
where tb_xz_salary._year=2004 and tb_xz_salary._month=2
更新成像你这样的结果值我没有做过,但是我类似的update句子~!
就想这样:
Update tb_xz_salary set NoworkHours=(select isnull(sum(tb_kq_nowork.NoWorkHours),0) from tb_kq_nowork where isnull(tb_kq_nowork.checker,'')<>'' and tb_kq_nowork.Emp_id=tb_xz_salary.Emp_id and tb_kq_nowork.Noworkdate>='2004-02-01' and tb_kq_nowork.Noworkdate<'2004-03-01' group by tb_kq_nowork.Emp_id) ,
NoworkPay=(select isnull(sum(tb_kq_nowork.Pay),0) from tb_kq_nowork where isnull(tb_kq_nowork.checker,'')<>'' and tb_kq_nowork.Emp_id=tb_xz_salary.Emp_id and tb_kq_nowork.Noworkdate>='2004-02-01' and tb_kq_nowork.Noworkdate<'2004-03-01' group by tb_kq_nowork.Emp_id)
where tb_xz_salary._year=2004 and tb_xz_salary._month=2
更新成像你这样的结果值我没有做过,但是我类似的update句子~!
#6
补充一下,我没有做过这么长的结果值,真的太长了,呵呵~
合在一起做,问题不大,应该是可以的!
合在一起做,问题不大,应该是可以的!
#7
可以
#8
我也没有做过这么长的结果值,真的太长了!其实你可以把这个语句写得更加简单
点的,
点的,
#9
其实两个sum值是在一个表中取得的,我只想统计一次就搞定,但这的话还是要分两次,不是太没效力,有没有类似insert into的语句一次搞定多个字段...........
#10
Update 绝对没有问题!
Update A
set A.Col1= B.Col1,
A.Col2= B.Col2
from AAA A
join (select Sum(sls) Col1, Sum(ada)Col2 from SSS ) B on (????)
Update A
set A.Col1= B.Col1,
A.Col2= B.Col2
from AAA A
join (select Sum(sls) Col1, Sum(ada)Col2 from SSS ) B on (????)
#11
当然能了
#12
可以得
#13
Update tb1 set a.Col1= b.Col1,a.Col2= b.Col2
from tb1 as a ,(select id,Col1,Col2 from tb2 ) as b
where a.id=b.id
from tb1 as a ,(select id,Col1,Col2 from tb2 ) as b
where a.id=b.id
#14
能