Arbaaz
Arbaaz

Reputation: 321

Inserting values into a column by derived from another column in the same table?

I have two columns in a table:

I am able to select the FlightNumber column with last 4 characters of each record.

 SELECT RIGHT(flightnumber, 4) FROM pnrdetails

But I am not sure how to insert this into the FlightId column. Suggestions?

Upvotes: 1

Views: 340

Answers (2)

Rab
Rab

Reputation: 35572

I guess , you dont need insert. you should be thinking about update. and I assume FlightId datatype is int.

 update pnrdetails set FlightId = convert(int,RIGHT(flightnumber, 4));

Upvotes: 1

Joe G Joseph
Joe G Joseph

Reputation: 24046

you could update the table

update pnrdetails
set FlightId =RIGHT(flightnumber, 4)

Upvotes: 0

Related Questions