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

  • SEARCH
  • Home
  • 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 8718317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:30:54+00:00 2026-06-13T06:30:54+00:00

Using SQL Server 2000 Table1 ID A001 A002 A003 A004 A005 A006 A007 ….

  • 0

Using SQL Server 2000

Table1

ID

A001
A002
A003
A004
A005
A006
A007
....
....
A028

From the above table, i want to split the 3 rows into 3 column, order by id

Rows display like this

Expected Output

id1 id2 id3

A001 A002 A003
A004 A005 A006
A007 A008 A009
...
...
A025 A026 A027
A028 null null

ID is not fixed, id may contain like this also (01A or A001 or 1A1 or etc....)

Table 1 row count is not fixed, it may goes more than 100 rows also. Column 3 is fixed. How to make a query for the above condition.

Need Query Help

  • 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-06-13T06:30:56+00:00Added an answer on June 13, 2026 at 6:30 am

    I would do it as follows:

    • Replace A with nothing in those IDs and convert them to integers
    • Write three SELECT statements where the condition will be integer ID calculated in above step %3 is 1, 2, 0 respectively, to yield the records in each row.
    • Now, we need to JOIN the results of these three SELECT statements and if you were on SQL Server 2005, then ROW_NUMBER() would have been handy, but since you are on SQL Server 2000, you would use IDENTITY(INT, 1, 1) to generate row numbers for each row in these SELECT statements and JOIN on this value.

    But since IDENTITY can be used in SELECT only with INTO clause, you would end up with temporary tables that contain each column and join on them.

    SELECT IDENTITY(INT, 1, 1) AS 'RowNum', ID FROM INTO #Row1 Table1
    WHERE CONVERT(INT, REPLACE(ID, 'A', '')) % 3 = 1
    
    SELECT IDENTITY(INT, 1, 1) AS 'RowNum', ID FROM INTO #Row2 Table1
    WHERE CONVERT(INT, REPLACE(ID, 'A', '')) % 3 = 2
    
    SELECT IDENTITY(INT, 1, 1) AS 'RowNum', ID FROM INTO #Row3 Table1
    WHERE CONVERT(INT, REPLACE(ID, 'A', '')) % 3 = 0
    
    SELECT 
        r1.ID id1,
        r2.ID id2,
        r3.ID id3
    FROM
        #Row1 r1
        FULL OUTER JOIN #Row2 r2
        ON r1.RowNum = r2.RowNum
        FULL OUTER JOIN #Row3 r3
        ON r3.RowNum = r3.RowNum
    
    DROP TABLE #Row1
    DROP TABLE #Row2
    DROP TABLE #Row3
    

    If you were on SQL Server 2005 or higher, all this could have been done in a single query as follows:

    SELECT 
        R1.ID,
        R2.ID,
        R3.ID
    FROM 
        (
            SELECT ROW_NUMBER() OVER (ORDER BY ID ASC) AS RowNum, ID 
            FROM ATABLE 
            WHERE 
                CONVERT(INT, REPLACE(ID, 'A', '')) % 3 = 1
        ) AS R1
        FULL OUTER JOIN (
            SELECT ROW_NUMBER() OVER (ORDER BY ID ASC) AS RowNum, ID 
            FROM ATABLE 
            WHERE 
                CONVERT(INT, REPLACE(ID, 'A', '')) % 3 = 2
        ) AS R2
        ON R1.RowNum = R2.RowNum
        FULL OUTER JOIN (
            SELECT ROW_NUMBER() OVER (ORDER BY ID ASC) AS RowNum, ID 
            FROM ATABLE 
            WHERE 
                CONVERT(INT, REPLACE(ID, 'A', '')) % 3 = 0
       ) AS R3
        ON R2.RowNum = R3.RowNum
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using SQL Server 2000 I want to compare the table2.date between table1.from, table1.todate, if
Using SQL Server 2000 table1 id values (datatype is nvarchar) 001 12:10 002 01:25
I am using SQL Server 2000 Table1 ID Date 001 23/02/2009 001 24/02/2009 002
Using SQL Server 2000 dtptime - datetimepicker (Format: Custom Format(HH:mm) Query insert into table1
Using SQL Server 2000 Table1 Id date --- ---------- 001 23/01/2012 002 25/01/2012 003
Using SQL Server 2000 Table1 ID Date Value1 Value2 001 01/01/2012 100 0 001
Using SQL Server 2000 and VB6 Table1 ID Date 001 20090801 001 20090802 …
Using SQL Server 2000 table1 id date time 001 01/02/2012 02:00 001 02/02/2012 01:00
Using sql server 2000 Table1 id value (float) 001 10.00 002 003 004 08.50
Using SQL Server 2000 Table1 ID Salary (Monthly) perday (salary) 001 3000 100 002

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.