GabrielVa
GabrielVa

Reputation: 2388

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.

Upvotes: 1

Views: 217

Answers (2)

Joe Stefanelli
Joe Stefanelli

Reputation: 135848

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

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

Upvotes: 1

dogbane
dogbane

Reputation: 274738

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

Upvotes: 0

Related Questions