Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Save a value
Message
 
To
24/11/2006 14:34:05
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
Environment versions
SQL Server:
SQL Server 2000
Miscellaneous
Thread ID:
01172323
Message ID:
01172325
Views:
15
>Hello.
>
>I have the next store procedure:
>
>CREATE PROCEDURE dbo.abc2
>@server varchar(20),
>@base varchar(20),
> AS
>DECLARE @pnCampo3 numeric(19,5)
>DECLARE @cad varchar(1000)
>set @pnCampo3 = 0.0
>set @cad='select MAX(NOTEINDX) from ['+@server+'].['+@base+'].[dbo].[SY03900] '
>exec(@cad)
>set @pnCampo3=@pnCampo3+1.0
>GO
>
>but I need get the value of [exec(@cad)] in a variable in order to add (1) to the result, for example if [exec(@cad)] = 5 I need get 5+1=6.
>
>I put somthing like this but is a error:
>set @pnCampo3=exec(@cad)
>
>How can I do this?


Try:
CREATE PROCEDURE dbo.abc2
@server varchar(20),
@base varchar(20),
AS
DECLARE @pnCampo3 numeric(19,5)
DECLARE @Nextvalue int
DECLARE @cad varchar(1000)
set @pnCampo3 = 0.0
set @cad='select @TestMe = MAX(NOTEINDX)+1 from ['+@server+'].['+@base+'].[dbo].[SY03900] '
SET @Nextvalue = 0
sp_executeSql @cad,'@TestMe int OUTPUT', @TestMe = @Nextvalue OUTPUT
SELECT @Nextvalue
set @pnCampo3=@pnCampo3+1.0
(not tested)
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform