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 |
|
EugeneLim11
Posting Yak Master
167 Posts |
Posted - 2008-06-25 : 02:19:15
|
| Hi experts,I got a a store procedure,CREATE PROCEDURE PROCEDURENAME @columnName varchar(50) ASBEGIN Insert into TableName(columnName1, PrimaryColumnName) values (@columnName, newID())ENDNow I have another table that use newID() as a foreign key. How do I retrieve the newID() value from the store procedure above so that I can use it as an input field in another table? Your help is very much appreciated. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-06-25 : 02:22:12
|
| Are you using SQL 2005? |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-06-25 : 02:23:34
|
[code]CREATE PROCEDURE PROCEDURENAME @columnName varchar(50), @PrimaryColumnName varchar(50) OUTPUTASBEGIN SELECT @PrimaryColumnName = NEWID() INSERT INTO TableName(columnName1, PrimaryColumnName) VALUES (@columnName, @PrimaryColumnName)END[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
EugeneLim11
Posting Yak Master
167 Posts |
Posted - 2008-06-25 : 02:26:30
|
| Thank you Khtan. I did not thought of using variables to hold the new ID(). This is a novel way of solving the problem. :) visakh16, I am using Visual Studio tied to MSSQL 2005 Database. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-06-25 : 02:28:21
|
quote: Originally posted by EugeneLim11 Thank you Khtan. I did not thought of using variables to hold the new ID(). This is a novel way of solving the problem. :) visakh16, I am using Visual Studio tied to MSSQL 2005 Database.
then you can even use thisCREATE PROCEDURE PROCEDURENAME @columnName varchar(50) ASBEGINInsert into TableName(columnName1, PrimaryColumnName) OUTPUT INSERTED.PrimaryColumnName INTO OtherTablevalues (@columnName, newID())END |
 |
|
|
|
|
|
|
|