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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:13:23+00:00 2026-06-12T09:13:23+00:00

A few minutes ago I was only searching for a simple syntax (SQL server)

  • 0

A few minutes ago I was only searching for a simple syntax (SQL server) query that will copy a table Row .

This is usually done from time to time, when working on a ASP.net project, testing data with queries
inside the SQL SERVER management studio . so one of the routine actions is copying a row, altering the required columns to be different from each other, then testing data with queries

So I’ve encountered – this stored procedure- ,as answer by Dan Atkinson

but adding it to where all non testing purpose are stored lead me to think
is it possible to store them in sorted order so I could Distinguish

‘utils’ or ‘testingPurpose’ ones from those used in projects

(default folder inside managment treeview is Programmabilty) could this be another folder too
or this is not an option ?

if not , I thought of Utils. prefix like that (if no other way exist)

dbo.Utils.CopyTableRow
dbo.Utils.OtherRoutineActions ....

Or there’s a designated way to achieve what I was thinking of.

  • 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-12T09:13:24+00:00Added an answer on June 12, 2026 at 9:13 am

    this is a first “Util” stored procedure i’ve made , found it’s only solution
    prefexing it via Util_

    ALTER PROCEDURE [dbo].[Utils_TableRowCopy](
    @TableName VARCHAR(50) ,
    @RowNumberToCopy INT
    )
    
    
    
    AS
    BEGIN
    
    declare @RowIdentity sysname =
    (SELECT name FROM sys.identity_columns WHERE object_id = object_id(@TableName)
     )
    
    DECLARE @columns VARCHAR(5000), @query VARCHAR(8000);
    SET @query = '' ;
    
    SELECT @columns =
        CASE
            WHEN @columns IS NULL THEN column_name
            ELSE @columns + ',' + column_name
        END
    FROM INFORMATION_SCHEMA.COLUMNS
    WHERE (
        TABLE_NAME = LTRIM(RTRIM(@TableName))
        AND
        column_name <> LTRIM(RTRIM(@RowIdentity))
    );
    
    SET @query = 'INSERT INTO ' + @TableName + ' (' + @columns + ') SELECT ' + @columns + ' FROM ' + @TableName + ' WHERE ' + @RowIdentity + ' = ' + CAST(@RowNumberToCopy AS VARCHAR);
    
    --SELECT SCOPE_IDENTITY();
    declare  @query2 VARCHAR(100) =  ' Select Top 1 * FROM '+ @TableName +' Order BY ' + @RowIdentity + ' desc' ;
    EXEC (@query);
    EXEC (@query2);
    

    END

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

Sidebar

Related Questions

THIS USER HAS ALREADY ASKED THE EXACT DUPLICATE A FEW MINUTES AGO sql and
Until a few minutes ago, I believed that Perl 's $ matches any kind
I learned few minutes ago that adding data attributes is a nice way to
a few minutes ago I had a discussion with my boss and want now
A few minutes ago, I commited some files and then pushed them to my
I was a bit surprised a few minutes ago when I tried to overload
I have a page that takes a few minutes to run. When I set
I currently have a python script that runs every few minutes and picks up
i just asked a question few minutes ago which led me to this one
This is another question related to a question I asked a few minutes ago.

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.