I'm having troubles pulling the id from the first insert to use on the second insert. Here's my SQL (I'm using stored procedures):
DECLARE @JoinDate date
DECLARE @ID int
SET @JoinDate = getdate()
EXEC Members_Add $(UserID), '$(UserName)',
@JoinDate, '$(firstname)', '$(lastname)', NULL,
'$(Country)', NULL, '$(stateorprovince)', '$(city)',
'$(ziporpostalcode)', '$(addressline1)', '$(addressline2)',
'$(MailCountry)', NULL, '$(mailstateprovince)', '$(MailCity)',
'$(mailzipcode)', '$(mailaddress)', NULL, NULL, NULL,
'$(mobilephone)', NULL, '$(Fax)', '$(Email)', NULL, NULL
SELECT @ID = SCOPE_IDENTITY()
EXEC Merchants_Add @ID, NULL, '$(BusinessName)', '$(CorporateName)',
'$(contactperson)', '$(OfficePhone)', '$(website)',
'$(DirectoryListing)', 'False'
I need to get the ID of the record added by the first stored procedure, I read up that you should use SELECT @@IDENTITY instead of SELECT Max(ID) but it doesn't seem to be working...
EDIT: I just updated the SELECT @@IDENTITY AS NEW_ID
to SELECT SCOPE_IDENTITY AS NEW_ID
and now I'm getting a cannot convert nvarchar to int error... any ideas?
EDIT #2: Updated the code again... now I'm getting cannot insert the vaule NULL
into column 'MemberID' that's the one that @ID
is in for the Merchants_Add
procedure.