Link to home
Start Free TrialLog in
Avatar of Queennie L
Queennie L

asked on

Join 2 tables and create date columns

Hello Experts,

I have 2 SQL tables A and B.

A table has all the dates in "Date" column.
B table has different values in "CodeNo" column.

What I want to output is join "Date" column in A table to B table.
Create "Date_1" column for the first "CodeNo" if then create another "Date_2" column for the rest of the values in "Date" column in A table.

Is this possible?
Thank you for all your help.
Join-2-tables-A-and-B.xlsx
Avatar of Tomas Helgi Johannsson
Tomas Helgi Johannsson
Flag of Iceland image

Hi,

The example data you provide tells me that the table B lacks some additional columns and data so
that you can do some simple SQL joins. I personally would have the date column in table B.
That would give you ability to use GROUP BY on STNo,InSNo and CodeNo columns and group the relevant dates together for further data manipulation.



Regards,
    Tomas Helgi
Avatar of Queennie L
Queennie L

ASKER

@TomasHelgi:

My problem is I cannot make it to create a new column.

Thank you for your help.
ASKER CERTIFIED SOLUTION
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
@slightwv:

I will test it and let you know.

Thank you again for your help.
@slightwv:

When I run this code, there is an error mydate and codeno invalid column names.

Thank you.
@slightwv:

It is my fault. I invert 2 tables in the wrong place.
@slightwv:

OMG! It is working.

Thank you for sharing your expertise and intelligence.

I really appreciate it.

Thank you also those who give their input.
Happy to help!