• Skip to main content
  • Skip to header right navigation
  • Skip to site footer
Foster Solutions (FSI)

Foster Solutions (FSI)

The Solution is in the Process

  • Home
  • What We Do
  • Case Studies
    • Databases/Automation Case Studies
    • GIS/Market Research Case Studies
    • Local Government Case Studies
    • FSI – crosspollination – examples
  • Articles

Copying Entire Row in SQL Server

May 26, 2010 by tech guys

It would be nice for SQL Server to copy rows like Excel. It is a pain to include all the fields.  Below is dynamic SQL to copy the entire row based on the auto id number:

[code]

declare @sql varchar(8000)
DECLARE @TableName varchar(100)
SELECT @tableName = ‘tblMyTable’   –put urTableName Here
SELECT @SQL = COALESCE(@sql+’,’,”)+ COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = @tableName AND COLUMNPROPERTY(OBJECT_ID(@tableName),COLUMN_NAME, ‘IsIdentity’) = 0

EXEC( ‘INSERT INTO ‘+@tableName+’ SELECT ‘+@SQL+’ FROM ‘+@TableName +’ WHERE auto_id  = theIDNum’) — put auto id fieldname and id num

[/code]

Category: Articles, SQL

Showcase Your Agency

Give your agency, business, or brand the sharp image it deserves with Mai Reach theme from BizBudding.

Buy Mai Reach Now

About tech guys

Previous Post:Converting SQL float field types
Next Post:porting WordPress manually w/ collation issues

Ready to get started?

Client Survey

Please take this survey if you are interested in a new or modified website. We will assess and get back with you as soon as possible.


Finding Solutions

We work with you to make things faster, easier and better.

  • Facebook
  • LinkedIn

Sites

  • Home
  • Blog
  • About
  • Features
  • Contact
  • Marketing

Features

  • Home
  • Blog
  • About
  • Features
  • Contact
  • Marketing

Support

  • Home
  • Blog
  • About
  • Features
  • Contact
  • Marketing

Copyright © 2025 · Foster Solutions (FSI) · All Rights Reserved

Back to top