Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
CA adding a record to table
Message
 
General information
Forum:
Visual FoxPro
Category:
Other
Environment versions
Visual FoxPro:
VFP 9 SP1
Miscellaneous
Thread ID:
01475186
Message ID:
01479788
Views:
46
>>>>Boris, my understanding (from some reading on-line) is that SCOPE_IDENTITY() is better than @@IDENTITY. So I am looking at the message you suggested that describes how to get SCOPE_IDENTITY(). And I am trying to understand the code Alekesy wrote. One thing I don't understand and maybe you can help me. In his code:
>>>>
>>>>
>>>>cInsertCmd = cInsertCmd + "; DECLARE @id int; SELECT @id = SCOPE_IDENTITY()" + ;
>>>>	"; EXEC #Get_ValHelper @id, ?@" + ;  
>>>>	this.Alias + "." + ALLTRIM(this.IDENTITY_Field)  
>>>>
>>>>
>>>>what is the purpose of EXEC #Get_ValHelper @Id? and "?@" ? Are these necessary?
>>>>
>>>>TIA
>>>
>>>
>>>To store the value of the @id in the VFP cursor field.
>>>I think the syntax should be:
>>>
>>>cInsertCmd = cInsertCmd + "; DECLARE @id int; SELECT @id = SCOPE_IDENTITY()" + ;
>>>	"; EXEC #Get_ValHelper @id, ?@" + ;  
>>>	this.Alias + "." + ALLTRIM(this.IDENTITY_Field) +" OUTPUT" 
>>>
>>
>>The syntax works OK as is. It's really tricky syntax, especially ?@Cursor.MyField -- I never knew you can use @ will fields, not with the memory variables or arrays.
>
>Hi Naomi,
>
>This is a message in the thread a few weeks ago on how to "refresh" identify column of a CA Cursor when adding a new record. I tried to use this approach in another project but get the following error:
>
>"Cannot use the Output option when passing a constant to a stored procedure"
>
>What I don't understand is, where is the constant? The code above passing variable "id" and a column name with alias. What am I missing? By the way, the following is my Stored Procedure:
>
>
>ALTER PROCEDURE [dbo].[Get_Identity_value] 
>	@in int,
>	@out int OUTPUT
>AS
>BEGIN
>	SET NOCOUNT ON;
>
>	set @out=@in
>    
>END
>
>
>Do you what I am missing? Thank you.

I don't get any error testing this SP in SQL Server:
create PROCEDURE [dbo].[Get_Identity_value] 
	@in int,
	@out int OUTPUT
AS
BEGIN
	SET NOCOUNT ON;

	set @out=@in
    
END
go
declare @out int
execute dbo.Get_Identity_value @in = 2, @out =@out output
select @out
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform