Solved

Duplicate row

Posted on 2009-07-15
2
201 Views
Last Modified: 2012-05-07
How do I duplicate a row where I change only value of 2 columns.
For example:

Table:  Id, M(int), N(int), Q(int), D(DateTime)

In the stored procedure I send @M and the new value of M @Mnewvalue
I want to set DateTime to current time in the new row.

For example:

Table (Before):
Id=1, M=5, N=7, Q=9, 2009-07-10...

@M=5
@Mnewvalue=8

Table(After)
Id=1, M=5, N=7, Q=9, 2009-07-10...
Id=2, M=8, N=7,Q=9, 2009-07-15
0
Comment
Question by:johnkainn
  • 2
2 Comments
 
LVL 31

Accepted Solution

by:
RiteshShah earned 250 total points
ID: 24858076
something like this will work


create proc ins
@m int,
@newM int
as
update table1 set d=getdate() where m=@m
insert into table1 (m,n,q,d)
select @newM,n,q,d from table1 where m=@m
go
0
 
LVL 31

Expert Comment

by:RiteshShah
ID: 24858115
I assume that ID is identity and don't need to provide in INSERT statement
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article will provide a solution for an error that might occur installing a new SQL 2005 64-bit cluster. This article will assume that you are fully prepared to complete the installation and describes the error as it occurred durin…
Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now