Hi I'm trying to loop through a SELECT and then build-up another tyable with INSERT per one record out of the SELECT statement:
I gets stuck with the INSERT command with: Field/Recor Buffer error: (HYT00 in SQLCommand INSERT ...........
Code:
Function BuildAllocTable() As Long
Local AllocRec As ALLOCRECORD
Local dwWeeks As Dword
Local dwWeek As Dword
Local dwYear As Dword
Local dblMHWeeks As Double
Local strSQLD As String
Local strSQLS As String
Local strSQLI As String
Local strTemp As String
Local I, J As Integer
strSQLD = "DELETE FROM x_allocations"
strSQLS = "SELECT Seq_User, Seq_Project, Seq_Request, YEAR(x_orders.Startdate), WEEK(x_orders.Startdate), "
strSQLS = strSQLS & "YEAR(x_orders.Duedate), WEEK(x_orders.Duedate), Manhours "
strSQLS = strSQLS & "FROM x_requests, x_orders "
strSQLS = strSQLS & "WHERE x_requests.Sequence = x_orders.Seq_Request AND "
strSQLS = strSQLS & "NOT ISNULL(x_orders.Startdate) AND NOT ISNULL(x_orders.Duedate) AND "
strSQLS = strSQLS & "Manhours <> 0 "
strSQLS = strSQLS & "ORDER BY Seq_User, Seq_Project, Seq_Request, x_orders.Startdate;"
strSQLI = "INSERT INTO x_allocations (Seq_User, Seq_Project, Seq_Request, Year, Week, Manhours) VALUES("
SQL_Stmt %SQL_STMT_IMMEDIATE, strSQLD
SQLCheckAndClose(SQL_State, strSQLD)
SQL_Stmt %SQL_STMT_IMMEDIATE, strSQLS
SQL_Fetch %NEXT_ROW
While Not SQL_EOD
AllocRec.dwUser = SQL_ResColSInt(1)
AllocRec.dwProj = SQL_ResColSInt(2)
AllocRec.dwReq = SQL_ResColSInt(3)
AllocRec.dwSY = SQL_ResColSInt(4)
AllocRec.dwSW = SQL_ResColSInt(5)
AllocRec.dwDY = SQL_ResColSInt(6)
AllocRec.dwDW = SQL_ResColSInt(7)
AllocRec.dwMH = SQL_ResColSInt(8)
'Calculate number of weeks (assuming 52 weeks per year)
If AllocRec.dwDY > AllocRec.dwSY Then
dwWeeks = (AllocRec.dwDY - AllocRec.dwSY) * 52
dwWeeks = (dwWeeks - AllocRec.dwSW) + AllocRec.dwDW + 1
Else
dwWeeks = AllocRec.dwDW - AllocRec.dwSW + 1
End If
dblMHWeeks = Round(AllocRec.dwMH / dwWeeks , 2)
dwYear = AllocRec.dwSY
dwWeek = AllocRec.dwSW
For i = 1 To dwWeeks
dwWeek = dwWeek + 1
If dwWeek > 52 Then
dwWeek = 1
dwYear = dwYear + 1
End If
strTemp = Str$(AllocRec.dwUser) & " ," & Str$(AllocRec.dwProj) & " ," & Str$(AllocRec.dwReq) & " ," & Str$(dwYear) & " ," & Str$(dwWeek) & ", " & Str$(dblMHWeeks)
MsgBox strTemp
strSQLI = strSQLI & Str$(AllocRec.dwUser) & ", " & Str$(AllocRec.dwProj) & ", " & Str$(AllocRec.dwReq) & ", "
strSQLI = strSQLI & Str$(dwYear) & ", " & Str$(dwWeek) & ", " & Str$(dblMHWeeks) & ");"
' Execute strSQLI
SQL_Stmt %SQL_STMT_IMMEDIATE, strSQLI
SQLCheckAndClose(SQL_State, strSQLI)
Next I
SQL_Fetch %NEXT_ROW
Wend
SQLCheckAndClose(SQL_State, strSQLS)
End Function
I gets stuck with the INSERT command with: Field/Recor Buffer error: (HYT00 in SQLCommand INSERT ...........
Code:
Function BuildAllocTable() As Long
Local AllocRec As ALLOCRECORD
Local dwWeeks As Dword
Local dwWeek As Dword
Local dwYear As Dword
Local dblMHWeeks As Double
Local strSQLD As String
Local strSQLS As String
Local strSQLI As String
Local strTemp As String
Local I, J As Integer
strSQLD = "DELETE FROM x_allocations"
strSQLS = "SELECT Seq_User, Seq_Project, Seq_Request, YEAR(x_orders.Startdate), WEEK(x_orders.Startdate), "
strSQLS = strSQLS & "YEAR(x_orders.Duedate), WEEK(x_orders.Duedate), Manhours "
strSQLS = strSQLS & "FROM x_requests, x_orders "
strSQLS = strSQLS & "WHERE x_requests.Sequence = x_orders.Seq_Request AND "
strSQLS = strSQLS & "NOT ISNULL(x_orders.Startdate) AND NOT ISNULL(x_orders.Duedate) AND "
strSQLS = strSQLS & "Manhours <> 0 "
strSQLS = strSQLS & "ORDER BY Seq_User, Seq_Project, Seq_Request, x_orders.Startdate;"
strSQLI = "INSERT INTO x_allocations (Seq_User, Seq_Project, Seq_Request, Year, Week, Manhours) VALUES("
SQL_Stmt %SQL_STMT_IMMEDIATE, strSQLD
SQLCheckAndClose(SQL_State, strSQLD)
SQL_Stmt %SQL_STMT_IMMEDIATE, strSQLS
SQL_Fetch %NEXT_ROW
While Not SQL_EOD
AllocRec.dwUser = SQL_ResColSInt(1)
AllocRec.dwProj = SQL_ResColSInt(2)
AllocRec.dwReq = SQL_ResColSInt(3)
AllocRec.dwSY = SQL_ResColSInt(4)
AllocRec.dwSW = SQL_ResColSInt(5)
AllocRec.dwDY = SQL_ResColSInt(6)
AllocRec.dwDW = SQL_ResColSInt(7)
AllocRec.dwMH = SQL_ResColSInt(8)
'Calculate number of weeks (assuming 52 weeks per year)
If AllocRec.dwDY > AllocRec.dwSY Then
dwWeeks = (AllocRec.dwDY - AllocRec.dwSY) * 52
dwWeeks = (dwWeeks - AllocRec.dwSW) + AllocRec.dwDW + 1
Else
dwWeeks = AllocRec.dwDW - AllocRec.dwSW + 1
End If
dblMHWeeks = Round(AllocRec.dwMH / dwWeeks , 2)
dwYear = AllocRec.dwSY
dwWeek = AllocRec.dwSW
For i = 1 To dwWeeks
dwWeek = dwWeek + 1
If dwWeek > 52 Then
dwWeek = 1
dwYear = dwYear + 1
End If
strTemp = Str$(AllocRec.dwUser) & " ," & Str$(AllocRec.dwProj) & " ," & Str$(AllocRec.dwReq) & " ," & Str$(dwYear) & " ," & Str$(dwWeek) & ", " & Str$(dblMHWeeks)
MsgBox strTemp
strSQLI = strSQLI & Str$(AllocRec.dwUser) & ", " & Str$(AllocRec.dwProj) & ", " & Str$(AllocRec.dwReq) & ", "
strSQLI = strSQLI & Str$(dwYear) & ", " & Str$(dwWeek) & ", " & Str$(dblMHWeeks) & ");"
' Execute strSQLI
SQL_Stmt %SQL_STMT_IMMEDIATE, strSQLI
SQLCheckAndClose(SQL_State, strSQLI)
Next I
SQL_Fetch %NEXT_ROW
Wend
SQLCheckAndClose(SQL_State, strSQLS)
End Function
Comment