Need help with SQL table structure transformation

Posted by Arnis L. on Stack Overflow See other posts from Stack Overflow or by Arnis L.
Published on 2010-03-08T15:43:11Z Indexed on 2010/03/08 15:51 UTC
Read the original article Hit count: 295

Filed under:
|
|

I need to perform update/insert simultaneously changing structure of incoming data.

Think about Shops that have defined work time for each day of the week.

Hopefully, this might explain better what I'm trying to achieve:

worktimeOrigin table:

columns:

  • shop_id
  • day
  • val

data:

  • 123 | "monday" | "9:00 AM - 18:00"
  • 123 | "tuesday" | "9:00 AM - 18:00"
  • 123 | "wednesday" | "9:00 AM - 18:00"

shop table:

columns:

  • id
  • worktimeDestination.id

worktimeDestination table:

columns:

  • id
  • monday
  • tuesday
  • wednesday

My aim:

I would like to insert data from worktimeOrigin table into worktimeDestination and specify appropriate worktimeDestination for shop.

shop table data:

  • 123
  • 1 (updated)

worktimeDestination table data:

  • 1 | "9:00 AM - 18:00" | "9:00 AM - 18:00" | "9:00 AM - 18:00" (inserted)

Any ideas how to do that?

© Stack Overflow or respective owner

Related posts about sql

Related posts about sql-server