Click here to Skip to main content
15,884,473 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi How Solve This Error

my code :
SQL
SET IDENTITY_INSERT UserProfile ON
GO
INSERT 
INTO UserProfile
SELECT
	up.UserId-2002,
	up.UserName,
	up.Name,
	up.Family,
	up.P_T,
	up.P_N,
	up.Reshteh,
	up.CodeOzviat,
	up.CodeParvaneh
FROM
	UserProfile up
WHERE        (UserId =2336)
GO
SET IDENTITY_INSERT UserProfile OFF


and error :

Msg 8101, Level 16, State 1, Line 1
An explicit value for the identity column in table 'UserProfile' can only be specified when a column list is used and IDENTITY_INSERT is ON.
Posted
Comments
ChauhanAjay 23-Aug-14 5:38am    
You will need to define the column names in the insert statement

insert into TestTable(id, text)
select '2', 'Value2'

1 solution

You forgot to specify the columns list in your INSERT command like:
SQL
SET IDENTITY_INSERT UserProfile ON
GO
INSERT 
INTO UserProfile (UserId, UserName, Name, Family, P_T, P_N, Reshteh, CodeOzviat, CodeParvaneh)
SELECT
	up.UserId-2002,
	up.UserName,
	up.Name,
	up.Family,
	up.P_T,
	up.P_N,
	up.Reshteh,
	up.CodeOzviat,
	up.CodeParvaneh
FROM
	UserProfile up
WHERE        (UserId =2336)
GO
SET IDENTITY_INSERT UserProfile OFF
 
Share this answer
 
Comments
NorouziFar 23-Aug-14 6:13am    
i use select, and i think not need command list
Raul Iloc 23-Aug-14 7:37am    
You need it, like also the error message said! Just try it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900