Jump to content
Sign in to follow this  
madsovenielsen

Timetable query

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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...