October 18, 2005 at 12:08 pm
Please help.
I am trying to add a duplicate row to the employee talble with one variation
this is a test case for mass duplicate insertions..
Declare @EmployeeID int
Declare @LastName nvarchar(20)
Declare @FirstName nvarchar(10)
Declare @Title nvarchar(30)
Declare @TitleOfCourtesy nvarchar(25)
Declare @BirthDate datetime
Declare @HireDate datetime
Declare @Address nvarchar(60)
Declare @City nvarchar(15)
Declare @Region nvarchar(15)
Declare @PostalCode nvarchar(10)
Declare @Country nvarchar(15)
Declare @HomePhone nvarchar(24)
Declare @Extension nvarchar(4)
--Declare @Photo image
--Declare @Notes ntext
Declare @ReportsTo int
Declare @PhotoPath nvarchar(255)
declare mycursor cursor for (Select top 1 EmployeeID ,LastName, FirstName, Title, TitleOfCourtesy, BirthDate, HireDate, Address , City, Region, PostalCode, Country, HomePhone, Extension, ReportsTo, PhotoPath
From Employees
Where Lastname = 'Davolio' AND
Birthdate ='12/8/1948'
 
open mycursor fetch next from mycursor into @EmployeeID , @LastName, @FirstName, @Title, @TitleOfCourtesy, @BirthDate, @HireDate, @Address , @City, @Region, @PostalCode, @Country, @HomePhone, @Extension, @ReportsTo, @PhotoPath
while @@fetch_status = 0
Begin
SET IDENTITY_INSERT Employees ON
set @Birthdate =18/8/1988
set @EmployeeID =Ident_current ('employees') + 1
insert into #tememp
Select
EmployeeID = @EmployeeID,
LastName= @LastName,
FirstName= @FirstName,
TitleOfCourtesy=@TitleOfCourtesy,
ostalCode=@PostalCode">PostalCode=@PostalCode,
Photo= null,
Notes = null ,
hotoPath=@PhotoPath">PhotoPath=@PhotoPath
From Employees
Where Lastname = 'Davolio' AND
Birthdate ='12/8/1948'
set nocount on
fetch next from mycursor into @EmployeeID , @LastName, @FirstName, @Title, @TitleOfCourtesy, @BirthDate, @HireDate, @Address , @City, @Region, @PostalCode, @Country, @HomePhone, @Extension, @ReportsTo, @PhotoPath
end
Close mycursor
Deallocate mycursor
results in the following
An explicit value for the identity column in table 'Employees' can only be specified when a column list is used and IDENTITY_INSERT is ON.
October 18, 2005 at 12:17 pm
Have you tried reading the help about identity insert?
There's a clue in the message even: column list is required.
It is the nature of identity columns to increment themselves, why do you feel compelled to use a cursor anyway? Why have an identity column if you want to control the value?
October 18, 2005 at 12:20 pm
The Message is loud and Clear
An explicit value for the identity column in table 'Employees' can only be specified when a column list is used and IDENTITY_INSERT is ON.
You have the Identity_insert part but you are missing the column list
insert into #tememp
(EmployeeID ,
LastName,
FirstName,
Title,
TitleOfCourtesy,
BirthDate,
HireDate,
Address ,
City,
Region,
PostalCode,
Country,
HomePhone,
Extension,
Photo,
Notes,
ReportsTo,
PhotoPath )
Select
EmployeeID = @EmployeeID,
LastName= @LastName,
FirstName= @FirstName,
TitleOfCourtesy=@TitleOfCourtesy,
<A href="mailtoostalCode=@PostalCode">PostalCode=@PostalCode,
Photo= null,
Notes = null ,
<A href="mailtohotoPath=@PhotoPath">PhotoPath=@PhotoPath
From Employees
Where Lastname = 'Davolio' AND
Birthdate ='12/8/1948'
hth
* Noel
October 18, 2005 at 12:34 pm
thanks, it's called not paying attention..
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply