Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
maevr
Posting Yak Master
169 Posts |
Posted - 2008-11-06 : 06:46:41
|
| I want to be able to copy a specific row in a table, how do I do this?I have tried to create a procedure that takes an id as argument, and based on this id I want to fetch the information from the different columns and store them in variables but I cannot get it to work, later on I wish to run an insert with the copied values to the same tableMy procedure:create procedure test(@myID int)asbegindeclare @name as char(20);declare @age as int;insert into @name values(select name from Person where id = @myID)insert into @age values(select age from Person where id = @myID)end |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-11-06 : 07:18:58
|
| create procedure test(@myID int)asbegindeclare @name as char(20);declare @age as int;select @name = name from Person where id = @myIDselect @age = age from Person where id = @myIDMadhivananFailing to plan is Planning to fail |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-11-06 : 07:19:39
|
| otr simplycreate procedure test(@myID int)asbegindeclare @name as char(20);declare @age as int;select @name = name,@age = age from Person where id = @myIDMadhivananFailing to plan is Planning to fail |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-06 : 07:30:33
|
| and make sure you have only one record satisfying the condition id = @myID else you might need table variable to store them |
 |
|
|
maevr
Posting Yak Master
169 Posts |
Posted - 2008-11-06 : 07:47:55
|
| Thanks!I got it to work before you posted, your solution was much better so I will use the one below.----create procedure test(@myID int)asbegindeclare @name as char(20);declare @age as int;select @name = name,@age = age from Person where id = @myID---- |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-11-06 : 07:56:29
|
quote: Originally posted by maevr Thanks!I got it to work before you posted, your solution was much better so I will use the one below.----create procedure test(@myID int)asbegindeclare @name as char(20);declare @age as int;select @name = name,@age = age from Person where id = @myID----
You are welcome MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|