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 |
|
shammad
Starting Member
3 Posts |
Posted - 2011-04-21 : 15:50:26
|
| Hi,I have two tables with 1 to many relationship, lets say 1- Device[ID] [int] IDENTITY(1,1) NOT NULL,[Name] [nvarchar] (50)2- Specs[ID] [int] IDENTITY(1,1) NOT NULL,[DeviceID] [int] NOT NULL,[DeviceType] [int] NOT NULLI need to insert the data using stored procedure, but the issue is I need to get the current device.Id to insert it in spec.deviceIDwhere the parameters for this procedure is (name and deviceType)please advise,thanks, |
|
|
midavis
Starting Member
23 Posts |
Posted - 2011-04-21 : 16:36:19
|
| INSERT INTO Device( [Name] )Values( 'Device1' )DECLARE @deviceId intset @deviceId = SCOPE_IDENTITY()INSERT INTO Specs( [DeviceID] , [DeviceType] )Values( @deviceId , 'Type1' ) |
 |
|
|
|
|
|