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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

grabbing just the last four digits... 1

Status
Not open for further replies.

leadman

Programmer
Jun 11, 2001
177
0
0
US
Im using the following to grab just the right four numbers from credit cards to be put in my database:

<cfset ccdbnumber=Right(#form.x_Card_Num#, 4)>

The problem is that if the last four digits are &quot;0045&quot; I get &quot;45&quot; in my database. is there a way to keep the zeros?
 
Hi LeadMan,
if the problem you are having is that it's going to the DB truncated but is OK on the screen, then its that you are storing the 4 digits as a number/integer, which will be truncated by the db. If you store it as a char(4) field, it should retain the length. Obviously for calculations etc, you'd have to change it back.
 
thanks - but since it is passed to my system as a number, how to I convert it to text?
 
Please clearify the last question. ColdFusion doesn't really differentiate much between numbers and strings. Are you going with the solution of chaning the db field to a Char(4) or are you staying with digit? - tleish
 
I was just what the code would look like. Since <cfset ccdbnumber=Right(#form.x_Card_Num#, 4)> produces a number, i need to convert it to text since my database will be expecting text, does this make sense?

 
The only thing you need to do is put the variable in single quotes in the query to pass it to the db as a string.

<cfset ccdbnumber = Right(form.x_Card_Num, 4)>

<cfquery...>
'#VARIABLES.ccdbnumber#'
</cfquery> - tleish
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top