updating day by day data in database using pentaho spoon - mysql

I have a SQL query as mentioned below and this will update DB every day comparing the date (latest appended date data will be updated in DB) and I want to do this in transformations using Pentaho Data Integration (Kettle).
Do While i < dgTest.RowCount
dd = Mid(dgTest.Item(2, i).Value, 5, 2) & "/" & Mid(dgTest.Item(2, i).Value, 7, 2) & "/" & Mid(dgTest.Item(2, i).Value, 1, 4)
Sql = "INSERT INTO cash ([comp], strno, bday, openread, curread,refqty,refamt, promoq," & _
" promoa, netsprod, netsnprod, eatintc, eatins, eatouttc, eatouts, " & _
" dttc, coffeetc, dts, coffeesales, csh, cover,recamt,crsalesamt ) Values " & _
" ('" & dgTest.Item(0, i).Value.ToString & "','" & dgTest.Item(1, i).Value.ToString & _
"',#" & CDate(dd) & "#,'" & dgTest.Item(3, i).Value.ToString & "'," & dgTest.Item(4, i).Value & "," & _
dgTest.Item(5, i).Value & "," & dgTest.Item(6, i).Value & _
"," & dgTest.Item(7, i).Value & _
"," & dgTest.Item(8, i).Value & "," & dgTest.Item(9, i).Value & _
"," & dgTest.Item(10, i).Value & "," & dgTest.Item(11, i).Value & _
"," & dgTest.Item(12, i).Value & "," & dgTest.Item(13, i).Value & "," & dgTest.Item(14, i).Value & _
"," & dgTest.Item(15, i).Value & "," & dgTest.Item(16, i).Value & "," & dgTest.Item(17, i).Value & "," & dgTest.Item(18, i).Value & "," & dgTest.Item(19, i).Value & "," & dgTest.Item(20, i).Value & "," & dgTest.Item(21, i).Value & "," & dgTest.Item(22, i).Value & ")"
cmd = New OleDbCommand(Sql, con)
cmd.ExecuteNonQuery()
i = i + 1
Loop

I don't understand the approach you are trying to implement but what you can do is from input table step read the data, use modified java-script and specify that on this particular time update the database.. example
var d = new Date();
var hour1 = d.getHours();
if(hour1==14)
{
if(d.getDate()==day2 && month1==month2 && year1==year2 && hour>=13 && hour<17)
}

Related

Access 2013 Edit Form error 3021

So I've got the code below (not all of it is grey for some reason)
Private Sub CmdEdit_Click()
Me.Tableinform.Requery
Dim rs As DAO.Recordset
Set rs = Me.Tableinform.Form.RecordsetClone
'get data to textbox control
With rs
If .RecordCount > 0 Then
With Me.Tableinform.Form.Recordset
Me.ShowIDbox = .Fields("[ID]").Value
Me.CompbyDD = .Fields("[Received By]")
Me.Date1 = .Fields("[Date Received]")
Me.Date2 = .Fields("[Date Processed]")
Me.ReqType = .Fields("[Request Type]")
Me.InsName = .Fields("[Insured Name]")
Me.RiskNo = .Fields("[Risk Number]")
Me.EndtRef = .Fields("[Endorsement Reference]")
Me.EOCNo = .Fields("[EOC Number]")
Me.Tech = .Fields("[Technician]")
Me.BillIns = .Fields("[Billing Instructions]")
Me.Addrecord.Caption = "Update"
Me.CmdEdit.Enabled = False
Me.cmdDuplicate.Enabled = True
Me.CmdDelete.Enabled = True
End With
End If
End With
End Sub
After one Edit and Update, the edit function throws out Error '3021' No Current Record?
Please show me where I am going wrong with this.
Add/Update button as follows:
If Me.ShowIDbox.Value = "" Then
CurrentDb.Execute "INSERT INTO fmdatatable( [Received By], [Date Received], [Date Processed], [Request Type], [Insured Name], [Risk Number], [Endorsement Reference], [EOC Number], [Technician], [Billing Instructions]) " & _
" VALUES ('" & Me.CompbyDD & "','" & Me.Date1 & "','" & Me.Date2 & "','" & Me.ReqType & "','" & Me.InsName & "','" & Me.RiskNo & "','" & Me.EndtRef & "','" & Me.EOCNo & "','" & Me.Tech & "','" & Me.BillIns & "')"
Else
CurrentDb.Execute "UPDATE fmdatatable SET [Received By]='" & Me.CompbyDD & "'" & _
", [Date Received]='" & Me.Date1 & "'" & _
", [Date Processed]='" & Me.Date2 & "'" & _
", [Request Type]='" & Me.ReqType & "'" & _
", [Insured Name]='" & Me.InsName & "'" & _
", [Risk Number]='" & Me.RiskNo & "'" & _
", [Endorsement Reference]='" & Me.EndtRef & "'" & _
", [EOC Number]='" & Me.EOCNo & "'" & _
", [Technician]='" & Me.Tech & "'" & _
", [Billing Instructions]='" & BillIns & "'" & _
" WHERE [ID]=" & Me.ShowIDbox.Value
End If
Me.CompbyDD = "-Please Select-"
Me.Date1 = ""
Me.Date2 = ""
Me.ReqType = "-Please Select-"
Me.InsName = ""
Me.RiskNo = ""
Me.EndtRef = ""
Me.EOCNo = ""
Me.Tech = ""
Me.BillIns = "-Please Select-"
Me.ShowIDbox = ""
Me.Addrecord.Caption = "Add Record"
Me.CmdEdit.Enabled = True
Me.cmdDuplicate.Enabled = False
Me.CmdDelete.Enabled = False
Tableinform.Form.Requery
This edit works once, then all subsequent later edits are throwing errors out.

Number format of a query in access vba

I created a query in access using VBA, and I want to change the number format of the last two columns to * #.##0,00;* (#.##0,00);* -00
I didn't find how to do it. Here's what I did:
Sub orcMensal(periodo As String)
Dim rs As QueryDef
Dim SQL1 As String
Dim ano As String
Dim tabelaCA As String
Dim tabelaRealizado As String
tabelaCA = "[ORCAMENTO_CA_20" & Right(periodo, 2) & "]"
tabelaRealizado = "[" & periodo & "_MA]"
SQL1 = "SELECT " & tabelaCA & ".coger AS [Codigo Coger], " _
& tabelaCA & ".[Descricao], " _
& tabelaCA & ".[" & periodo & "] AS [Orcamento], " _
& tabelaRealizado & ".[REALIZADO] AS [Realizado], " _
& "(" & tabelaRealizado & ".[REALIZADO] - " & tabelaCA & ".[" & periodo & "]) AS [Diferenca] " _
& "FROM " & tabelaCA _
& " INNER JOIN " & tabelaRealizado & " ON" _
& " (" & tabelaCA & ".[coger] = " & tabelaRealizado & ".[COD_ES] AND " _
& tabelaCA & ".[Titular] = " & tabelaRealizado & ".[TITULAR]);"
Debug.Print SQL1
Set rs = CurrentDb.CreateQueryDef(periodo, SQL1)
DoCmd.OpenQuery rs.Name, , acReadOnly
End Sub
I used the Format function in the SQL query, like #Wayne G. Dunn commented. The format that I wanted was
1) 1000000,5023 >>>> 1.000.000,50;
2) -5200000,7833 >>>> (5.200.000,78);
3) 0 >>>> -
So I used '#,##0.00; (#,##0.00); -' in the format function, here's how the query looks:
SQL1 = "SELECT " & tabelaCA & ".coger AS [Codigo Coger], " _
& tabelaCA & ".[Descricao], " _
& "Format(" & tabelaCA & ".[" & periodo & "], '#,##0.00; (#,##0.00); -') AS [Orcamento], FORMAT(" _
& tabelaRealizado & ".[REALIZADO], '#,##0.00; (#,##0.00); -') AS [Realizado], " _
& "Format((" & tabelaRealizado & ".[REALIZADO] - " & tabelaCA & ".[" & periodo & "]), '#,##0.00; (#,##0.00); -') AS [Diferenca] " _
& "FROM " & tabelaCA _
& " LEFT JOIN " & tabelaRealizado & " ON" _
& " (" & tabelaCA & ".[coger] = " & tabelaRealizado & ".[COD_ES] AND " _
& tabelaCA & ".[Titular] = " & tabelaRealizado & ".[TITULAR])" _
& "WHERE " & tabelaCA & ".coger <> '';"

Too few parameters, expected 4;

Dim query As String
query = "insert into tbl_passenger(passenger_name,age,gender_id,address,phone_no,plane_no,seat_no,destination_id,time_id,price_id)values('" & _
Me.txtpassengername.Value & "'," & Me.txtage.Value & "," & Me.cmbgender.Column(1) & ",'" & Me.txtaddress.Value & "', " & Me.txtphone.Value & "," & _
Me.cmbplane.Column(1) & "," & Me.cmbseat.Column(1) & "," & Me.cmbdestination.Column(1) & "," & Me.cmbtime.Column(1) & "," & _
Me.cmbprice.Column(1) & ")"
CurrentDb.Execute (query)
MsgBox ("Data Inserted")
What is the problem here? The error I get is
Too few parameters, expected 4;
Insert a debug line:
Debug.Print query
CurrentDb.Execute (query)
MsgBox ("Data Inserted")
Study what you see, and you will know. Or post the output here.

Run-time error '3061': Too Few Parameters. Expected 2

So I'm trying to teach myself VBA again and I'm having a cople of troubles. I'm trying to add new users to a table but keep getting the above error when I click my "Update" button. The text field will be in the form of 2 letters and 5 numbers. XX11111 for example.
Private Sub cmdAdd_Click()
'when we click on button Add there are two options
'1. for insert
'2. for update
If Me.txtLoginName.Tag & "" = "" Then
'add data to table
CurrentDb.Execute "INSERT INTO tblUsers(LoginName,UserName,Rank) " & _
" VALUES('" & Me.txtLoginName & "','" & Me.txtUsername & "','" & Me.cboRank & "')"
Else
CurrentDb.Execute "UPDATE tblUsers " & _
"set LoginName=" & Me.txtLoginName & "'" & _
", UserName='" & Me.txtUsername & "'" & _
", Rank='" & Me.cboRank & "'" & _
" WHERE LoginName=" & Me.txtLoginName.Tag
End If
'clear form
cmdClear_Click
'refresh data in list on form
frmModifyUsersSub.Form.Requery
End Sub
you are missing a ' in this line:
" set LoginName=" & Me.txtLoginName & "'" & _
change it to
" set LoginName='" & Me.txtLoginName & "'" & _
and :
" WHERE LoginName=" & Me.txtLoginName.Tag
to
" WHERE (LoginName='" & Me.txtLoginName.Tag & "')" ' and I don't know if this your intended where condition.
The error pretty much gives you the answer. You need 2 parameters for the function it is failing on. One thing to try is to change
CurrentDb.Execute "INSERT INTO tblUsers(LoginName,UserName,Rank) " & _
" VALUES('" & Me.txtLoginName & "','" & Me.txtUsername & "','" & Me.cboRank & "')"
and
CurrentDb.Execute "UPDATE tblUsers " & _
"set LoginName=" & Me.txtLoginName & "'" & _
", UserName='" & Me.txtUsername & "'" & _
", Rank='" & Me.cboRank & "'" & _
" WHERE LoginName=" & Me.txtLoginName.Tag
To
CurrentDb.Execute "INSERT INTO tblUsers(LoginName,UserName,Rank) " & _
" VALUES('" & Me.txtLoginName & "','" & Me.txtUsername & "','" & Me.cboRank & "')",dbFailOnError
and
CurrentDb.Execute "UPDATE tblUsers " & _
"set LoginName='" & Me.txtLoginName & "'" & _
", UserName='" & Me.txtUsername & "'" & _
", Rank='" & Me.cboRank & "'" & _
" WHERE LoginName='" & Me.txtLoginName.Tag & "'", dbFailOnError

number of query values and destination fields are not the same

This is what I have for the Add Event.
CurrentDb.Execute "INSERT INTO tblMatchBook ([Patron], [Staff], [TimeReceived], [SurveyLink], [DateFinished], [BookTitles]) " & _
" Values('" & Me.ddBarcode & "," & Me.ddStaff & "," & Me.txtRDate & "," & Me.txtLink & "," & "" & "," & "" & "')"
I cannot figure out what is wrong.
insert into Main values (28494,1,False,'Buto-asma Sirop' , 'Buto-asma Sirop', 3.99 , 'Syrup', 'ispani', ' ', ' ',0, '1',4988 )