Skip to content
Advertisement

What should I do to join two columns with different name but has the same data type, so that I can get something I need from one of the table?

I have two table, [table a] and [table b]. So basically, I need work_week from [table a] therefore I want to join the columns together, shift_begin_datetime from [table a] and shift_start_datetime from [table b] as both of them have the same data type but they have different name.

I want both of the column to be renamed as shift_start_dt and after combining the result should be something like this.

And is it possible to display work_week and …….. (representing the rest of the data)?

I was also wondering if there is no data for the certain column, will it return as null?

I have tried union all for both of the table into a temp table, but I do not know how can I get work_week out of it. But I think union cant allow me to get work_week out of it, therefore, I’m not sure what else solution I can do. Here’s what I did:

Advertisement

Answer

See if this helps you too, COALESCE and FULL OUTER JOIN are used:

Reference: https://learn.microsoft.com/en-us/sql/t-sql/language-elements/coalesce-transact-sql?view=sql-server-ver16

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement