Skip to content
Advertisement

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.

Advertisement

Answer

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

update TableA
    set Col1 = (select Col1 from TableB)
    where Col1 is null
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement