Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3219160
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:36:46+00:00 2026-05-17T15:36:46+00:00

We have a table like below in an sql server 2005 db: event_id staff_id

  • 0

We have a table like below in an sql server 2005 db:

event_id   staff_id   weeks

1          1          NNNYYYYNNYYY
1          2          YYYNNNYYYNNN
2          1          YYYYYYYYNYYY

This is from a piece of timetabling software and is basically saying which staff members are assigned to an event (register) and the set of weeks they are teaching that register. So staff_id 1 isn’t teaching the first 3 weeks of event 1 but is teaching the following 4….

Is there an easy way to convert that to an easier form such as:

event_id   staff_id   week
1          1          4
1          1          5
1          1          6
1          1          7
1          1          10
1          1          11
1          1          12
1          2          1
1          2          2
1          2          3
1          2          7
1          2          8
1          2          9
2          1          1
2          1          2
2          1          3
2          1          4
2          1          5
2          1          6
2          1          7
2          1          8
2          1          10
2          1          11
2          1          12
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T15:36:47+00:00Added an answer on May 17, 2026 at 3:36 pm
    WITH cte AS
    (
        SELECT 1 AS [week]
        UNION ALL
        SELECT [week] + 1
        FROM cte
        WHERE [week] < 53
    )
    SELECT t.event_id, t.staff_id, cte.[week]
    FROM your_table AS t
        INNER JOIN cte
            ON LEN(ISNULL(t.weeks, '')) >= cte.[week]
                AND SUBSTRING(t.weeks, cte.[week], 1) = 'Y'
    ORDER BY t.event_id, t.staff_id, cte.[week]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have one table sql server like below , from that table i want
I have a table in SQL Server that is structured like this: id Name
Using SQL Server 2005, I have a table where certain events are being logged,
SQL Server 2000 Say if I have a table like CREATE TABLE [Message] (
Note: This issue appears to be limited to SQL Server 2005 SP2 I have
i have a sql table full of address' like this Hattie:07903 000066::Dad:07854 000095::Tom:07903 000044::Allistair:07765
I have designed a stored procedure usign Sql Server 2005 below to compare 3
In SQL server 2008, I have below table Score. I want to show Score1
Imagine I have table like this: id:Product:shop_id 1:Basketball:41 2:Football:41 3:Rocket:45 4:Car:86 5:Plane:86 Now, this
I have a table like this: <table> <tfoot> <tr><td>footer</td></tr> </tfoot> <tbody> <tr><td>Body 1</td></tr> <tr><td>Body

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.