?
Solved

Increment & return current generator value

Posted on 2002-06-24
3
Medium Priority
?
546 Views
Last Modified: 2013-12-09
How can I return the current generator id value using sql.  I want to be able to run a sql query in my code to increment and return the current value.

I would like something like to work, but of course it doesn't:

select GEN_ID (ORDER_ID_GEN, 1) AS ORDER_ID;

I don't want to increment the value based on an insert into a table.

Thanks in advance.
Chris
0
Comment
Question by:cjclayton
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 2

Accepted Solution

by:
IPCH earned 200 total points
ID: 7106666
Try this:

CREATE PROCEDURE ND (
  MYINC INTEGER
) RETURNS (
  AVALUE INTEGER
) AS  
begin
avalue = gen_id(NUM_DS,:MYINC);
SUSPEND;
end

and this:

SELECT * FROM ND(1)

Ivan
0
 

Author Comment

by:cjclayton
ID: 7109384
Thank you Ivan.  Here is my working version:

/* Procedure: "GET_ORDER_ID" */
/* Usage: SELECT * FROM GET_ORDER_ID(1) */

SET TERM !! ;
CREATE PROCEDURE GET_ORDER_ID ( MYINC INTEGER ) RETURNS ( ORDER_ID INTEGER )
AS
begin
  order_id = gen_id(ORDER_ID_GEN,:myinc);
  SUSPEND;
END !!
SET TERM ; !!
0
 
LVL 2

Expert Comment

by:IPCH
ID: 7109927
You are wellcome.

Ivan
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Azure Functions is a solution for easily running small pieces of code, or "functions," in the cloud. This article shows how to create one of these functions to write directly to Azure Table Storage.
In this article, we’ll look at how to deploy ProxySQL.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question