Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

formatting a recurring id number.

Status
Not open for further replies.

devondago

Programmer
Jan 22, 2003
38
US
I have a query where I need to create a reccuring id. As of now I create a table in sql that recurs starting at number 101. here is the code I use.
<cflock timeout=&quot;3&quot; throwontimeout=&quot;No&quot; name=&quot;mylock&quot; type=&quot;EXCLUSIVE&quot;>
<cfquery name=&quot;getrid&quot; datasource=&quot;#dsn#&quot;>
select recurid from recuridtest
</cfquery>
<cfoutput><cfset rid = #getrid.recurid# + 1></cfoutput>
<cfquery name=&quot;upid&quot; datasource=&quot;#dsn#&quot;>
UPDATE recuridtest
SET recurid = #rid#
</cfquery>

</cflock>
This is where I am getting a little lost. Since the recurring id generates a 3 digit number I need to find a way to add a letter plus 8 zeros. I want my number to look like this on the output T00000000101.
The only reason I need this format is because my final insert is going to be made into an Oracle db that has been formatted to hold a length of 12 digits.
my insert statements looks something like this
<cfquery name=&quot;addEvent&quot; datasource=&quot;test&quot;>
Insert Into test_data.event
(
xname
xnumber
)
Values
(
#xname#
#rid#
)

All help will be appreciated. :)
 
Replace:
<cfset rid = #getrid.recurid# + 1>

With:
<cfset rid=&quot;T&quot; & numberformat(rid + 1,&quot;00000000000&quot;)>
 
Typo in previous post...

Replace:
<cfset rid = #getrid.recurid# + 1>

With:
<cfset rid=&quot;T&quot; & numberformat(getrid.recurid + 1,&quot;00000000000&quot;)>
 
Since ColdFusion is a weakly typed language, you can just append the leading 9 characters as a string. You do want to make sure that you format your 3 digit number to have leading zeros if it will ever have a value less than 100, but that's easily done with NumberFormat. Here's an example:

<cfset strFormattedNumber = &quot;T00000000&quot; & NumberFormat(intYourNumber, &quot;000&quot;)>

Then you just use strFormattedNumber as the value you insert into the database.

Hope this helps!
 
Thanks for taking the time to asnwer and for the feedback. I tried it out and it works...
:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top