开发者

how to add new column in ms access table with this criteria

开发者 https://www.devze.com 2022-12-21 20:49 出处:网络
i have two msaccess tables tableA textA nu开发者_如何转开发mA bd1 as0 aa2 cc4 tableB textB ss aa bd as how to write an sql query to add one column called numB in table B so that final table B

i have two msaccess tables

tableA

textA nu开发者_如何转开发mA
bd    1
as    0
aa    2
cc    4

tableB

textB 
ss
aa
bd
as

how to write an sql query to add one column called numB in table B so that final table B would be

tableB ( basically fetching values from tableA )

textB  numB
ss     0      ( because ss is not there in table A )
aa     2
bd     1
as     0


This SQL will make a new table called tblFooC

SELECT tblFooB.TextB, nz([NumA],0) AS Expr1 INTO tblFooC
FROM tblFooB LEFT JOIN tblFooA ON tblFooB.TextB = tblFooA.TextA;

You could then delete table tblFooB and rename tblFooC to tblFooB


You cannot do this in one query. You can create TableC from tables A & B and then rename and/or delete so that table C becomes table B, or you can run a DDL query to add a column to Table B. I suggest the second option.

To add a column:

ALTER TABLE TableB ADD COLUMN NumB Integer

To update:

UPDATE TableA 
RIGHT JOIN TableB ON TableA.TextA = Tableb.TextB 
SET TableB.BumB = Nz([NumA],0);
0

精彩评论

暂无评论...
验证码 换一张
取 消