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 8709139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:17:49+00:00 2026-06-13T04:17:49+00:00

how to create sql server cte from a while loop my loop like this

  • 0

how to create sql server cte from a while loop
my loop like this

  declare @ind as int
  declare @code as nvarchar
  set @ind  = 0
   while @ind < 884
  begin
    select @ind  = @ind  + 1
    --here execute Procedure 
        --and set return value to variable 
    set @code = cast (@ind   as nvarchar)
  end
  • 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-13T04:17:50+00:00Added an answer on June 13, 2026 at 4:17 am

    If you need table:

    ;WITH Sec(Number) AS 
    (
        SELECT 0 AS Number
        UNION ALL
        SELECT Number + 1
        FROM Sec
        WHERE Number < 884
    ) 
    
    SELECT * FROM Sec
    OPTION(MAXRECURSION 0)
    

    If you need one string:

    ;WITH Sec(Number) AS 
    (
        SELECT 0 AS Number
        UNION ALL
        SELECT Number + 1
        FROM Sec
        WHERE Number < 884
    ) 
    
    SELECT STUFF(a.[Str], 1, 1, '')
    FROM
    (
        SELECT (SELECT ',' + CAST(Number AS NVARCHAR(3)) 
        FROM Sec
        FOR XML PATH(''), TYPE
        ).value('.','varchar(max)') AS [Str] 
    ) AS a
    OPTION(MAXRECURSION 0)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know how to create a job dynamically from this create-sql-server-job-automatically The issue I
SQl Server 2005: Option: 1 CREATE TABLE #test (customerid, orderdate, field1 INT, field2 INT,
I have a sql server table: CREATE TABLE [Workflow].[MilestoneDate]( [MilestoneDateId] [int] IDENTITY(1,1) NOT NULL,
SQL Server 2008. declare @pardate table ( pardateid int, pardatewhen datetime2(3) ) insert into
I want create MenuStrip dynamic (in winform C#.Net 4.0) From Database (SQL Server) and
What is the right order in which we should create SQL Server objects? (This
Has anyone managed to create a CTE in SQL Server's T-SQL that also includes
I have following this link to create my SQL Server database during installation of
im using sql server 2005. I have these tables: CREATE TABLE [dbo].[Proyectos2]( [Id] [int]
I am trying to create an add-in by using the article below http://blogs.microsoft.co.il/blogs/shair/archive/2008/07/28/how-to-create-sql-server-management-studio-addin.aspx I

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.