简体   繁体   中英

SQL Inserting Data into table

I have a SQL table, let's call it "Table A", which has several rows of data. I then have a temp table called "Table b" that has one row of data. I want to be able to do a sql insert so that if Table A Column 1 is null, it will insert Table B Column 1's value.

So I'd wind up with something like this:

Table A
Col1  Col2  Col3
23    John  Smith
23    Sam   Jones
23    Jim   Ham

Table B
Col1
23

Can someone explain how I might go about doing this? Any help will be appreciated.

You say insert, but I think you're asking for an update.

update TableA
    set Col1 = (select Col1 from TableB)
    where Col1 is null
update tableA set col1 = (select col1 from tableB)
where col1 is null

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM