Avatar of rquirion
rquirion
Flag for Canada asked on

Return multiple rows from a value in another column

I have this

teamID    someValue

7              2
8              3

I want this

7              1
7              2
8              1
8              2
8              3

I want to return multiple rows based on the value in column "somevalue"
Microsoft SQL Server

Avatar of undefined
Last Comment
rquirion

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
deighton

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
deighton

you may eventually need a


;WITH CTE AS (SELECT MAX(SomeValue) as X FROM YourTable
                        UNION ALL
                        SELECT X - 1 FROM CTE WHERE x>1)
                       
      SELECT E.SomeValue TeamId, C.X YourNewValues FROM YourTable E
       JOIN CTE C ON C.X <= E.SomeValue
       ORDER BY E.SomeValue , C.x
       option(maxrecursion 0)
selva_kongu

try this




SELECT DISTINCT A.ID, A.Code, A.ownerName, B.Count
FROM Team A
JOIN (
  SELECT COUNT(*) as Count, B.Code
  FROM team B
  GROUP BY B.Code
) AS B ON A.Code = B.Code
WHERE B.Count > 1
ORDER by A.Code;
rquirion

ASKER
worked perfect. Thank you
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy