Home > database >  Questions about a function!
Questions about a function!

Time:10-02

1, after the new maximum serial number and assign values to the data window
2, after the new record saved to the database, update the current largest serial number
Details: I created a function: wf_getmaxno () I need to show the form of a field for "BG. 10001" (when no records in the database of the initial value)
If express meaning not clear I say detailed point, under the environment

CodePudding user response:

Didn't see,,,

CodePudding user response:


Strig s_dm, s_maxdm

The select Max (id) into: s_dm from table;

If the sqlca. Sqlcode=100 then
S_maxdm=left (s_dm, 3) + string (integer (s_dm, 5) (right) + 1)
The else
S_maxdm="BG. 10001"
End the if
Return s_maxdm

CodePudding user response:

Write the
Strig s_dm, s_maxdm

The select Max (id) into: s_dm from table;

If the sqlca. Sqlcode=100 then//empty table
S_maxdm="BG. 10001"

The else
S_maxdm=left (s_dm, 3) + string (integer (s_dm, 5) (right) + 1)

End the if
Return s_maxdm

CodePudding user response:

I have written before get maximum value and automatic assignment "HT20080708001
"


String ls_no
String ls_maxno
String ls_like
String ls_3

Ls_like=string (wi_nvo_server uf_servertime (), "yyyymmdd")
Ls_like ls_like="HT" + + "%
"
The select Max (hetonghao) into: ls_maxno
The from hetongh where hetonghao like: ls_like;

If isnull (ls_maxno) then ls_maxno=""
Ls_maxno=trim (ls_maxno)

If ls_maxno="" then
Ls_no=left (ls_like, 10) + "001"
The else
Ls_3=right (ls_maxno, 3)
Ls_no=left (ls_like, 10) + string (integer (ls_3) + 1, "000")
End the if


Return ls_no


But for BG. 10001 won't cough up ha ha just learning soon forgive me

CodePudding user response:

Is your custom parameters?

CodePudding user response:

String ls_no
String ls_maxno
String ls_like
String ls_3

Ls_like="BG. 1%"

The select Max (hetonghao) into: ls_maxno
The from hetongh where hetonghao like: ls_like;

If isnull (ls_maxno) then ls_maxno=""
Ls_maxno=trim (ls_maxno)

If ls_maxno="" then
Ls_no="BG. 10001"
The else
Ls_3=right (ls_maxno, 4)
Ls_no='BG. 1 + string (integer (ls_3) + 1, "0000")
End the if


Return ls_no

CodePudding user response:

refer to the sixth floor of AFIC reply:
string ls_no
String ls_maxno
String ls_like
String ls_3

Ls_like="BG. 1%"

The select Max (hetonghao) into: ls_maxno
The from hetongh where hetonghao like: ls_like;

If isnull (ls_maxno) then ls_maxno=""
Ls_maxno=trim (ls_maxno)

If ls_maxno="" then
Ls_no="BG. 10001"
The else
Ls_3=right (ls_maxno, 4)
Ls_no='BG. 1 + string (integer (ls_3) + 1, "0000")
End the if


Return ls_no

CodePudding user response:

If it is the primary key advice directly in a similar database sequence to deal with,
Directly to get the maximum without control database isolation level concurrent easily lead to heavy number,

CodePudding user response:

With sequence is a good choice

CodePudding user response:

The
refer to the original poster pbxinshou posts:
1, after the new , and
assign values to the data window2, after the new record saved to the database, to update the current largest serial number

Don't do it usually, because in multi-user mode, the serial number and update the serial number, there will be other operations between may lead to multiple users have the same serial number,
Generally have the following several ways to achieve generated id number:
1, sybase identity fields, oracle sequence, can automatically generate serial number, and automatic incremental, and atomic operation, not afraid of heavy number
2, the use of the guid, do not need to maintain maximum serial number, support distributed environment
3, build the biggest serial number list, custom incremental algorithm, the serial number increment and return in a stored procedure, call when data save, must be finished in a single transaction

CodePudding user response:

String ls_1, ls_no
The integer li_1
Ls_1='BG.'
The select Max (id) into: ls_no from the table where the left (id, 3)=: ls_1 using the sqlca.
If the sqlca. Sqlcode & lt;> 0 then
Ls_no='BG. 10001'
The else
Ls_no=ls_1 + string (long (right (ls_no, len (ls_no) - pos (ls_no, '. '))) + 1)
End the if
Return ls_no
  • Related