Suppose I have 2 databases DB1, DB2 under same instance. I have 2 tables in each database like:
tab1(id1, ...): --id1 is identity column in DB1
tab2(id2,...) : --id2 is identity column in DB2
I have following codes in DB1 SP:
use DB1
declare @id2 int;
insert into tab1(...) values (...);
insert into DB2.dbo.tab2(...) values (...);
set @id2 = SCOPE_IDENTITY();
but I can't get the right value for id2, it is null. How to resolve this problem?