Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Dynamic sql with return value
Message
General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Miscellaneous
Thread ID:
00704008
Message ID:
00704049
Views:
19
Thanks

>Take a look at my How to return a value from dynamicaly executed T-SQL code FAQ #8130.
>
>>How can I get a return value returned from dynamic sql? I want to pass a field and a table name and return the max value of the field.
>>
>>ALTER   FUNCTION fn_MaxId
>>   (@pkfield varchar(30) = 'iactionid',
>>    @tablename varchar(30) = 'ACTIONLOG'
>>    )
>>RETURNS bigint
>>AS
>>BEGIN
>>	DECLARE @Res bigint
>>	DECLARE @sqlstring varchar(1000)
>>	SET @Res = 1
>>	set @sqlstring = N'select max('+@pkfield+N') as nextid from '+@tablename
>>	exec @sqlstring
>>        -- How can I get the max value into the @Res return value???
>>	RETURN ( @Res )
>>END
>>
Previous
Reply
Map
View

Click here to load this message in the networking platform