Using Character Functions
Description
In some plants, for example a steel factory, they like to keep batch numbers
on everything they make. These numbers look like W96-123. The following stored
procedure will create the W96-123 form with only the number 123 being supplied
to it.
Example Stored Procedure
CREATE PROCEDURE W96(n integer)
RETURNS (batch char(10)) AS
BEGIN
/*
We need to combine together, some characters, the year and an integer to
create W96-123.
The functions we will use are:
cstradd(s1,s2) - concatenates strings s1 and s2
year("now") - returns the year from a date
"now" - a constant that returns the current date
str_plus_int(s,i) - converts an Integer I to a string and concatentates
it with the string
*/
batch = str_plus_int(cstradd(str_plus_int("W",(year("now")-1900)),"-"),n) ;
END!!
WISQL - calling the pmnt stored procedure
execute procedure w96(123);
BATCH
==========
W96-123
execute procedure w96(2123);
BATCH
==========
W96-2123
Notes:
This is a start but you could have it retrieve the number for the batch from
an InterBase generator thereby eliminating the need to pass it a number and
guaranteeing that the batch numbers will be unique.