Duplicate row

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...


Id=1, M=5, N=7, Q=9, 2009-07-10...
Id=2, M=8, N=7,Q=9, 2009-07-15
Who is Participating?
RiteshShahConnect With a Mentor Commented:
something like this will work

create proc ins
@m int,
@newM int
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
I assume that ID is identity and don't need to provide in INSERT statement
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.