Microsoft
Software
Hardware
Network
Question : How to return the new inserted value for identity column ?
Any there possible to return inserted value for an indentity column? i know this is possible to using 'Output' on SQL 2005. Please advise. Thanks.
Example on SQL 2005:
CREATE TABLE dbo.EmployeeSales
( EmployeeID int IDENTITY (1,5)NOT NULL,
LastName nvarchar(20) NOT NULL,
FirstName nvarchar(20) NOT NULL,
CurrentSales money NOT NULL,
ProjectedSales AS CurrentSales * 1.10
);
GO
DECLARE @MyTableVar table(
LastName nvarchar(20) NOT NULL,
FirstName nvarchar(20) NOT NULL,
CurrentSales money NOT NULL
);
INSERT INTO dbo.EmployeeSales (LastName, FirstName, CurrentSales)
OUTPUT INSERTED.LastName,
INSERTED.FirstName,
INSERTED.CurrentSales
INTO @MyTableVar
SELECT c.LastName, c.FirstName, sp.SalesYTD
FROM HumanResources.Employee AS e
INNER JOIN Sales.SalesPerson AS sp
ON e.EmployeeID = sp.SalesPersonID
INNER JOIN Person.Contact AS c
ON e.ContactID = c.ContactID
WHERE e.EmployeeID LIKE '2%'
ORDER BY c.LastName, c.FirstName;
Answer : How to return the new inserted value for identity column ?
Hello alankwan,
try
SELECT @@IDENTITY
Random Solutions
Sendmail Log Incoming & Outgoing Email With Ease
What is my SID? host?
How Do I create pivot query in t-sql for I-Anywhere
Get a HTTP POST with a C# Handler
Exchange 2003 as Backup Domain Controller
Which DR solution is better - Microsoft CCR or Xosoft Wansync HA for Exchange?
VPN Windows Mobile 5&6 Exchange server Checking e-mail
Printing with TCP/IP with HP Jet Direct
Need to query and change the format output of a date column. Currently comming out as yyyy-mm-dd : 00:00:00.000
Mounting CDROM