hi evry one
is there any problem with my code it dos'nt returen any value
please help
CREATE PROCEDURE [dbo].[mMaxId]
AS
set nocount on
declare @.Id bigint
declare @.mID bigint
select @.id = max(TransId) from tbltransaction
if (@.id is null)
begin
set @.mid = 1
end
if ( @.id is not null)
begin
set @.mid = @.id +1
end
return
GOWhat is it supposed to return ? Mid , ID ? Then you have to specify an outpu
t
paramter to catch the value from the calling procedure, if you have a
resultset you can use the resultset by inserting that in temp table while
executing
Insert into #SomeTable
EXEC(Someprocedure)
--
HTH, Jens Suessmeyer.
http://www.sqlserver2005.de
--
"mowafy" wrote:
> hi evry one
> is there any problem with my code it dos'nt returen any value
> please help
> CREATE PROCEDURE [dbo].[mMaxId]
> AS
> set nocount on
> declare @.Id bigint
> declare @.mID bigint
> select @.id = max(TransId) from tbltransaction
> if (@.id is null)
> begin
> set @.mid = 1
> end
> if ( @.id is not null)
> begin
> set @.mid = @.id +1
> end
> return
> GO
>|||Hi
Although you can use a select statement to return @.mid as a result set,
depending on what your requirements are, it may be more efficient to use an
output parameter
CREATE PROCEDURE [dbo].[mMaxId] @.mID bigint OUTPUT
AS
set nocount on
SET @.mid =ISNULL(SELECT max(TransId) from dbo.tbltransaction ),0) + 1
return
GO
DECLARE @.nextId bigint
EXEC [dbo].[mMaxId] @.nextId OUTPUT
...
If you are only wanting this number to allocate unique numbers to the
transaction id, then an identity column may be an easier way to implement
this functionality (although they may not be contiguous). You will need to
make sure that you don't write the code in such a way that two processes can
use the same transaction id.
John
"mowafy" wrote:
> hi evry one
> is there any problem with my code it dos'nt returen any value
> please help
> CREATE PROCEDURE [dbo].[mMaxId]
> AS
> set nocount on
> declare @.Id bigint
> declare @.mID bigint
> select @.id = max(TransId) from tbltransaction
> if (@.id is null)
> begin
> set @.mid = 1
> end
> if ( @.id is not null)
> begin
> set @.mid = @.id +1
> end
> return
> GO
>
No comments:
Post a Comment