Equivalent SQL Command of index match (excel) to update column in existing table

I need to update an existing table by adding a new column. Below is the sample data for the first table which needs to be updated with the new column(Ticket_No_Calc).

First

And here is the sample data of the second table.

Column A Column B
Ticket_No Doc_No

F20184343243243 18C5B3023924
F20193434342222 18C5B3023533
F20194343222323 19C560001043
F20134354547772 18S700000269
F20184585955430 19C560001044
P24545465656435 19C5B3003445
F45454340302020 19C560001045
F24455020202020 19C560001047

In Excel, I use this formula in order to get the output for the new column (Ticket_No_Calc).

=IFERROR(IF(D2="MKT",INDEX(Second!A:A,MATCH(First!B2,Second!B:B,0),0),INDEX(Second!A:A,MATCH(First!C2,Second!B:B,0),0)),INDEX(Second!A:A,MATCH(First!A2,Second!B:B,0),0)

I am not sure on how to translate this formula into SQL command. Could someone please help me with this please

Thank you.