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

ODBC Error!!

Status
Not open for further replies.

micjohnson

Programmer
Nov 9, 2000
86
US
Hi there!

When i am updating or inserting a table, i am getting this error always.

ODBC Error Code = 22001 (String data right truncation)


[Microsoft][ODBC SQL Server Driver][SQL Server]String or binary data would be truncated.



The error occurred while processing an element with a general identifier of (CFQUERY), occupying document position (101:3) to (101:58).

Can anybody tell me plse why its coming?

Thanx
micjohnson
 
Hi eagle1wi


Thanx for your reply! Here is my code.Its is a big one. Please have a patience to look at this. I think the problem is in the Loop.

<CFIF Group IS &quot;Staff&quot;>
<CFSET RTable = &quot;StaffRegTable&quot;>
<CFSET Code = &quot;Spec_Code&quot;>
<CFELSE>
<CFSET RTable = &quot;RegTable&quot;>
<CFSET Code = &quot;Spec_code&quot;>
</cfif>
<CFIF Departure IS &quot;Y&quot;>
<CFSET Time_in_first_half=#Cookie.First#>
<CFSET Time_out_second_half=#Cookie.Second#>
</CFIF>


<HTML><HEAD>
<TITLE><CFOUTPUT>#Group#</CFOUTPUT> Attendence Submitted</TITLE>

<CFINCLUDE TEMPLATE=&quot;shortheaders-light.cfm&quot;>

</HEAD>
<BODY>

<div align=&quot;center&quot;><img src=&quot;resources/dcflag.gif&quot; alt=&quot;&quot; border=&quot;0&quot;></div>

<CFIF Group IS NOT &quot;Staff&quot;>
<CFSET Time = &quot;Time_in_first_half&quot;>
<CFELSE>
<CFSET Time = &quot;Hours&quot;>
</CFIF>

<CFSET AttendanceArray=ArrayNew(2)>
<CFSET ListsArray=ArrayNew(1)>
<CFSET ListsArray[1]=&quot;Spec_Code&quot;>
<CFSet ListsArray[2]=&quot;Time_in_first_half&quot;>
<CFSET ListsLength=ArrayLen(ListsArray)>
<CFIF Departure IS &quot;N&quot;>
<CFSET List=&quot;Spec_code, #Time#&quot;>
<CFELSE>
<CFSET List=&quot;Spec_code, Time_in_first_half, Time_out_second_half&quot;>
</CFIF>

<CFSET incount=1>
<CFLOOP INDEX=&quot;innercounter&quot; LIST=&quot;#List#&quot;>
<CFSET loopcount=1>
<CFLOOP INDEX=&quot;outercounter&quot; LIST=&quot;#Evaluate(&quot;#innercounter#&quot;)#&quot;>
<CFSET AttendanceArray[#incount#][#loopcount#] = &quot;#outercounter#&quot;>
<CFIF innercounter IS &quot;Spec_code&quot;>
<CFSET PresentVar = &quot;Present#Evaluate(&quot;#outercounter#&quot;)#&quot;>
<CFSET PresVar = &quot;Present#Evaluate(&quot;#outercounter#&quot;)#&quot;>
<CFIF NOT Evaluate(&quot;ParameterExists(#PresVar#)&quot;)>
<CFSET AttendanceArray[#incount#+2][#loopcount#] = &quot;N&quot;>
<CFELSE>
<CFSET AttendanceArray[#incount#+2][#loopcount#] = Evaluate(&quot;Present#outercounter#&quot;)>
</CFIF>
</CFIF>
<CFSET loopcount = #loopcount#+1>
</CFLOOP>
<CFSET incount = #incount#+1>
</CFLOOP>


<CFSET temp=ArrayLen(AttendanceArray)>

<CFSET temp2=ArrayLen(AttendanceArray[temp])>

<CFSET insertCount = 0>
<CFSET Time_out=&quot;12:00 AM&quot;>
<CFSET Time_in_2nd=&quot;12:00 AM&quot;>
<CFSET Time_out_2nd=&quot;12:00 AM&quot;>
<CFOUTPUT>
<CFSET String_Date=#DateFormat(Now(), &quot;mm/dd/yy&quot;)#>
</CFOUTPUT>
<TABLE width=&quot;70%&quot; ALIGN=&quot;CENTER&quot;>

<CFOUTPUT>
<CFSET loopcount=1>
<CFLOOP FROM=&quot;1&quot; TO=&quot;#ArrayLen(AttendanceArray[temp])#&quot; INDEX=&quot;OuterCounter&quot;>
<TR>
<CFLOOP INDEX=&quot;InnerCounter&quot; FROM=&quot;1&quot; TO=&quot;#temp#&quot;>
</CFLOOP>
</TR>
<CFIF AttendanceArray[3][outercounter] IS &quot;Y&quot;>


<CFQUERY NAME=&quot;Attendcheck&quot; DATASOURCE=&quot;DC_Schools&quot;>
SELECT *
FROM dbo.Daily_Rec, dbo.#RTable#
WHERE dbo.Daily_Rec.String_Date = '#DateFormat(Now(),&quot;mm/dd/yy&quot;)#' AND dbo.Daily_Rec.Spec_code = dbo.#RTable#.#Code#
</CFQUERY>


<CFLOOP QUERY=&quot;Attendcheck&quot;>
<CFIF AttendanceArray[1][outercounter] IS #Attendcheck.Spec_code#>
<TR><TD ALIGN=&quot;CENTER&quot;><BR>Attendance for #Attendcheck.First_Name# #Attendcheck.Last_Name# has already been recorded. Please click the Back or Previous button on your browser and try again.</TD></TR>
<CFABORT>
</CFIF>
</CFLOOP>



<CFQUERY NAME=&quot;DailyAttendance&quot; DATASOURCE=&quot;DC_Schools&quot;>
INSERT INTO dbo.Daily_Rec (<CFIF Group IS NOT &quot;Staff&quot;>Time_in_first_half<CFELSE>Hours, Time_in_first_half</CFIF>, Spec_code, Time_Out_First_half, Time_out_second_half, Time_in_second_half, String_Date)
VALUES ('#AttendanceArray[2][outercounter]#', <CFIF Group IS &quot;Staff&quot;>'12:00 AM', </CFIF>'#AttendanceArray[1][outercounter]#', '#Time_out#', '#Time_out_2nd#', '#Time_in_2nd#', '#String_Date#')
</CFQUERY>

<!--- Catch the Database Exception and Errors--->


<CFSET insertCount=#insertCount#+1>
<CFELSE>
<CFIF Departure IS &quot;Y&quot;>
<CFQUERY name=&quot;DailyDeparture&quot; datasource=&quot;DC_Schools&quot;>
UPDATE Daily_Rec
SET <!---Time_in_first_half='#AttendanceArray[2][outercounter]#',---> Time_out_second_half='#AttendanceArray[3][outercounter]#'
WHERE Spec_Code='#AttendanceArray[1][outercounter]#' AND String_Date='#DateFormat(Now(), &quot;mm/dd/yy&quot;)#'
</cfquery>

<CFSET insertCount=#insertCount#+1>
</CFIF>
</CFIF>

</CFLOOP>
</CFOUTPUT>

</TABLE>




<CFSET AttendanceList=ArrayNew(2)>
<CFSET loopcount=1>

<cfloop index=&quot;Spec_codeList&quot; list=&quot;#Spec_code#&quot;>
<CFSET AttendanceList[loopcount][loopcount]=#Spec_codeList#>
<cfloop INDEX=&quot;TimeIn&quot; LIST=&quot;#Time#&quot;>
<CFSET AttendanceList[loopcount][loopcount+1]=#TimeIn#>
</CFLOOP>
<CFOUTPUT>
<CFSET PresentVar = &quot;Present#Spec_codeList#&quot;>
<CFSET PresVar = &quot;Present#Spec_codeList#&quot;>
<CFIF NOT Evaluate(&quot;ParameterExists(#PresVar#)&quot;)>
<CFSET Present = &quot;N&quot;>
<CFELSE>
<CFSET Present = Evaluate(&quot;Present#Spec_codeList#&quot;)>
</CFIF>
</cfoutput>

<CFSET loopcount=#loopcount#+1>
</cfloop>

<BR>
<div align=&quot;center&quot;><FONT size=&quot;+1&quot;><B>Attendance was successfully recorded for <CFOUTPUT>#insertCount# #Group#</CFOUTPUT><CFIF insertcount GT 1>s</cfif> </B></FONT></div><br><br><br>

<BR>
<div align=&quot;center&quot;><a href=&quot;DCPSAttendMenu.cfm&quot;><font size=&quot;+1&quot; color=&quot;Red&quot;>Return to Attendance Menu</font></a></div>
</BODY></HTML>

Thanx
micjohnson

 
Nothing jumps out at me. Maybe it will for someone else. If you could post the structure of your database(s) field widths,types etc that may be helpful. I still bet you are overfilling a field. What database are you using? I would try checking your date fields. They can be very picky about formatting. What line is 101?
 
Hi eagle1wi

Thanx for your reply!. I too feel that it may overfilling a field.

Here is the table structure.

Table Name: daily_rec


Field Datatype Length

Spec_Code char 10 Time_In_First_half char 8
Time_Out_First_half char 8
Time_In_Second_half char 8
Time_Out_Second_half char 8
Attendence_Date char 8
Attendence_Code char 7
String_Date char 8
Present char 1
Snack char 1
Hours char 2
Shift char 2
School_Name char 32
AM_Teacher char 10
PM_Teacher char 10

Thanx
micjohnson
 
I think your are inserting/update a field with the size larger than specified in table.
For example if you are inserting more than 2 characters for &quot;Shipt&quot; field you will get this error. you may have to use left function to truncate the field value while inserting.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top