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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:51:17+00:00 2026-05-30T13:51:17+00:00

My query is as below declare @row_id int = 2 declare @last_row_id int =(select

  • 0

My query is as below

declare @row_id int = 2
declare @last_row_id int  =(select MAX(Row_ID) from dbo.Source)

create table #source  (
    Row_ID float null,
      [Document] [nvarchar](255) NULL,    
      [ITEMCode] [nvarchar](255) NULL,    
      [Text] [nvarchar](255) NULL)

while(@row_id<=(@last_row_id))
begin

declare @Document nvarchar(255)
declare @itemcode nvarchar(255)

select @itemcode=ITEMCode,@Document=Document from dbo.Source where Row_ID=@row_id


if ((@itemcode='' or @itemcode is null ) )
select @itemcode=ITEMCode,@Document=Document from #source where Row_ID=@row_id-1

insert into #source
select Row_ID,@Document,@itemcode,[Text]
from dbo.Source where Row_ID=@row_id

print @row_id

set @row_id= @row_id+1

end

select * from #source
drop table #source

Presently my table has 347000 rows .its taking more than a hour to get me final output . how can this query made faster . Can anyone help ?

Requirement :

Source :

  Row_ID    Document    ITEMCode     Text                   
    2      10223         20235       aaaa
    3                                    bbbb
    4                                    cccc
    5      10278         202475      xxxx
    6                                    yyyy
    7                                    yyy

Output should be :

 Row_ID  Document  ITEMCode Text    
   2       10223     20235  aaaa
   3       10223     20235  bbbb
   4       10223     20235  cccc
   5       10278    202475  xxxx
   6       10278    202475  yyyy
   7       10278    202475  yyy
  • 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-30T13:51:18+00:00Added an answer on May 30, 2026 at 1:51 pm

    Even though above specified queries might work , I wrote a macro in excel which we quire fast n got the output in less than 5 min

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please look into the below query declare @t table(roleid int null,EmailAddress varchar(50) null) insert
I have a query like below declare @str_CustomerID int Insert into IMDECONP38.[Customer].dbo.CustomerMaster ( CustomerName
While trying to execute the below query Declare @t table (id int, string varchar(1000))
Could you help me to check as below: DECLARE @tblCity TABLE (CityID INT, CityName
I'm using the below query to return results from a table using Full-Text-Search. In
Take the tsql query below: DECLARE @table TABLE(data VARCHAR(20)) INSERT INTO @table VALUES ('not
I am trying get the values using SP.The query is below. create proc [dbo].[GetOrdersByUserID11]
Why does the MySQL query below give error 1066 (Not unique table/alias: 'customer') ?
I have a problem with the query below in postgres SELECT u.username,l.description,l.ip,SUBSTRING(l.createdate,0,11) as createdate,l.action
Please have a look at the below SQL code. DECLARE @RET TABLE(OID BIGINT NOT

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.