Solved

Increment & return current generator value

Posted on 2002-06-24
3
513 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
  • 2
3 Comments
 
LVL 2

Accepted Solution

by:
IPCH earned 50 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This article explains all about SQL Server Piecemeal Restore with examples in step by step manner.
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

757 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now