March 7, 2013 at 9:02 am
Hi,
I need a query which will have an input parameter @SerNum1, the query will copy all the ParamNum, ParamVal, Lock and Id of that serial number.
Now I will send in a new @SerNum2 and this new SerNum2 will be inserted into the same table, column and all that copied data of the first SerNum1 will be pasted next to the new SerNum2.
Please look at the attached PNG file for the structure of the table and cloumns.
March 7, 2013 at 9:47 am
So, in essence, given @SerNum1 (let us call it A) and @SerNum2 (call it B) you want to insert @SerNum2 with all the values of @SerNum1. Is this correct?
March 7, 2013 at 9:49 am
Thats Correct.
Thanks and Regards
March 7, 2013 at 9:52 am
Start with this:
create table #Serials (
SerNum varchar(36),
ParamNum int,
ParamValue varchar(32),
Lock int,
Id int
);
insert into #Serials(
SerNum,
ParamNum,
ParamValue,
Lock,
Id
)
select
@SerNum2,
s.ParamNum,
s.ParamValue,
s.Lock,
s.Id
from
#Serials s
where
s.SerNum = @SerNum1;
March 7, 2013 at 10:00 am
Thanks for the quick response Lynn. I already have a table called tblConfig, I think I need a stored procedure or some sort of a cursor which will copy the values of @SerNum1 and insert a new @SerNum2 with all the copied values in the existing table tblConfig, column: SerNum
Thanks for your help again.
March 7, 2013 at 10:02 am
harleen.suri (3/7/2013)
Thanks for the quick response Lynn. I already have a table called tblConfig, I think I need a stored procedure or some sort of a cursor which will copy the values of @SerNum1 and insert a new @SerNum2 with all the copied values in the existing table tblConfig, column: SerNumThanks for your help again.
No cursor, no loops. Just change my temp table name to your table name.
March 7, 2013 at 10:05 am
As a stored proc:
create procedure dbo.CopySerial(
@pSourceSerNum varchar(36), -- or whatever data type it is
@pTargetSerNum varchar(36) -- again change to match your data types
)
as
insert into dbo.tblConfig(
SerNum,
ParamNum,
ParamValue,
Lock,
Id
)
select
@pTargetSerNum,
s.ParamNum,
s.ParamValue,
s.Lock,
s.Id
from
dbo.tblConfig s
where
s.SerNum = @pSourceSerNum;
go
March 7, 2013 at 10:11 am
Thats what i needed. Thanks a lot Lynn - you are a star! 🙂
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply