Question : Moving stored procedure from SQL Server 2000 to 2005, multiple table inserts and SCOPE_IDENTITY

Hi,

I'm moving some tables & stored procedures from SQL Server 2000, to SQL Server 2005.

So far so good, but I've come across a problem with this stored procedure:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
CREATE PROCEDURE [dbo].[user_insert]
@user_service_unit int,
@user_champion_1 varchar(50),
@user_champion_1_nt varchar(10),
@user_champion_2 varchar(50),
@user_champion_2_nt varchar(10),
@user_champion_3 varchar(50),
@user_champion_3_nt varchar(10),
@user_date_received datetime,
@user_requestor varchar(255),
@user_info_requested text,
@user_expiry_date datetime,
@user_10_days datetime,
@user_5_days datetime,
@user_2_days datetime
AS

INSERT INTO dbo.user_details
(user_service_unit, user_champion_1, user_champion_1_nt, user_champion_2, user_champion_2_nt, user_champion_3, user_champion_3_nt, 
user_date_received, user_requestor, user_expiry_date, user_10_days, user_5_days, user_2_days)
VALUES
(@user_service_unit, @user_champion_1, @user_champion_1_nt, @user_champion_2, @user_champion_2_nt, @user_champion_3, @user_champion_3_nt, 
@user_date_received, @user_requestor, @user_expiry_date, @user_10_days, @user_5_days, @user_2_days);

DECLARE @new_id INT
SET @new_id = SCOPE_IDENTITY()

INSERT INTO dbo.user_info_requested
(user_id, user_info_requested)
VALUES
(@new_id, @user_info_requested)

INSERT INTO dbo.user_details_supplied
(user_id, user_details_supplied)
VALUES
(@new_id, '')

INSERT INTO dbo.user_questions
(user_id, user_questions)
VALUES
(@new_id, '')

RETURN @new_id
GO


On SQL Server 2000 it inserts the main record into user_details, then the extra blank records into the other 3 tables using the @new_id from the SCOPE_IDENTITY.
And then returns @new_id back so I can use it in my ASP.net script.

On SQL Server 2005, @new_id is null, and nothing is ever inserted, not even into user_details.

All permissions are set correctly on the stored procudure, and tables.

Any ideas or hints what I have to change?

Cheers,
Mike

Answer : Moving stored procedure from SQL Server 2000 to 2005, multiple table inserts and SCOPE_IDENTITY

are you 200% sure you moved the table with the identity property set on the column(s) as needed?
that is the only reason I can think of of the scope_identity returning null after the insert
please double-check
Random Solutions  
 
programming4us programming4us