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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 manually increment values of ID field

Author  Topic 

TajKazi
Posting Yak Master

101 Posts

Posted - 2014-11-04 : 05:15:58
declare @kk int
set @kk=0
insert into tblSSAppsOrgEntityToEmployerMapDiffer
( Id,
OrgEntityCode,
EmployerId,
[Default],
Active,
CreatedBy,
CreatedOn,
ModifiedBy,
ModifiedOn)
select @kk+1,
entity,
employer,
[default],
active,
created_by,
created_on,
modified_by,
modified_on
from tblSSAppsOrgEntityToEmployerMapTemp



in above example Id is PK for Differ tbl and Temp tbl not having field related to this. thats why i have to take and increment that Id value manually.... but like above way i m getting error ............ please somebody help me

TajKazi
Posting Yak Master

101 Posts

Posted - 2014-11-04 : 07:16:42
without using identity
Go to Top of Page

vaibhavktiwari83
Aged Yak Warrior

843 Posts

Posted - 2014-11-04 : 07:51:29
Try this -

declare @kk int
set @kk=0
insert into tblSSAppsOrgEntityToEmployerMapDiffer
( Id,
OrgEntityCode,
EmployerId,
[Default],
Active,
CreatedBy,
CreatedOn,
ModifiedBy,
ModifiedOn)
select ROW_NUMBER() OVER ( ORDER BY (SELECT 1) ),
entity,
employer,
[default],
active,
created_by,
created_on,
modified_by,
modified_on
from tblSSAppsOrgEntityToEmployerMapTemp


Vaibhav T

If I cant go back, I want to go fast...
Go to Top of Page

TajKazi
Posting Yak Master

101 Posts

Posted - 2014-11-05 : 00:27:26
vaibhavktiwari83
.......thanx a very lot
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2014-11-05 : 06:44:35
See this to know what all you can do with row_number() function
http://beyondrelational.com/modules/2/blogs/70/posts/10802/multipurpose-rownumber-function.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

TajKazi
Posting Yak Master

101 Posts

Posted - 2014-11-06 : 07:11:11
thanks to all of U
Go to Top of Page
   

- Advertisement -