Jump to content

Timetable query


madsovenielsen
 Share

Recommended Posts

HelloI know this is a total newb question, but i have the following SQL:

SELECT FagNavn, adgangskrav, Ugedag, holdId, fagKode, CONVERT(CHAR(10), StartDato, 105) AS startDate, CONVERT(CHAR(10), slutDato, 105) AS endDate, afdeling, link, navn, deltagerBetaling, bt, niveau, Case When Ugedag = 'Mandag' Then frakl + ' - ' + tilkl Else '' End AS startSlutMandag, Case When Ugedag = 'Tirsdag' Thenfrakl + ' - ' + tilkl Else '' End AS startSlutTirsdag, Case When Ugedag = 'Onsdag' Thenfrakl + ' - ' + tilkl Else '' End AS startSlutOnsdag, Case When Ugedag = 'Torsdag' Then frakl + ' - ' + tilkl Else '' End AS startSlutTorsdag, Case When Ugedag = 'Fredag' Thenfrakl + ' - ' + tilkl Else '' End AS startSlutFredag FROM [VisWebHoldSkema] ORDER BY afdeling

This is giving me records with each weekday (Ugedag) like this:

+--------+-----------------+------------------+-----------------+------------------+-----+ | holdId | startSlutMandag | startSlutTirsdag | startSlutOnsdag | startSlutTorsdag | ... |+--------+-----------------+------------------+-----------------+------------------+-----+| 1587b1 | 09:00 - 15:30   |                  |                 |                  | ... |+--------+-----------------+------------------+-----------------+------------------+-----+| 1587b1 |                 | 08:00 - 15:00    |                 |                  | ... |+--------+-----------------+------------------+-----------------+------------------+-----+| 1587b1 |                 |                  | 08:30 - 18:00   |                  | ... |+--------+-----------------+------------------+-----------------+------------------+-----+| 1587b1 |                 |                  |                 | 15:00 - 04:00    | ... |+--------+-----------------+------------------+-----------------+------------------+-----+

But i need the days to be in the same record, like this:

+--------+-----------------+------------------+-----------------+------------------+-----+| holdId | startSlutMandag | startSlutTirsdag | startSlutOnsdag | startSlutTorsdag | ... |+--------+-----------------+------------------+-----------------+------------------+-----+| 1587b1 | 09:00 - 15:30   | 08:00 - 15:00    | 08:30 - 18:00   | 15:00 - 04:00    | ... |+--------+-----------------+------------------+-----------------+------------------+-----+

Some sample data from the db:

 

 

Any ideas?

data.txt

Edited by madsovenielsen
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...