Solved

Increment & return current generator value

Posted on 2002-06-24
3
517 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
CCModeler offers a way to enter basic information like entities, attributes and relationships and export them as yEd or erviz diagram. It also can import existing Access or SQL Server tables with relationships.
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…

863 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

23 Experts available now in Live!

Get 1:1 Help Now