benkingery
Registered User.
- Local time
- , 21:34
- Joined
- Jul 15, 2008
- Messages
- 153
[FONT=Verdana, Arial, Helvetica]I have an inventory management database that I use to manage multiple channel online sales. The platform is SQL, but the front end I've been using is MS Access because of familiarity. I have the following VB code in a module in Access that makes a record-set out of the current onhand inventory from a transaction ledger and then updates another table with those numbers so we can evaluate inventory across multiple channels at the same time.
Access takes about 25 minutes to run through this procedure and I know SQL could do it much quicker plus I could automate the update. Can anyone out there give me any ideas as to how to do something similar in SQL? I have a pretty advanced knowledge of Access, but more of a moderate to beginning level knowledge of SQL.
Thanks in advance for anyone's help!
Public Function UpdateAZOnhand()
Dim cnn1 As ADODB.Connection
Set cnn1 = CurrentProject.Connection
Dim myRecordSet As New ADODB.Recordset
myRecordSet.ActiveConnection = cnn1
Dim mySql As String
mySql = "SELECT AZ_Transactions.Item, Sum([AZ_Transactions.QTY]*IIf(Type='Credit',1,-1)) AS CurrentOnhand FROM AZ_Transactions GROUP BY AZ_Transactions.Item"
DoCmd.SetWarnings False
myRecordSet.Open (mySql)
While Not myRecordSet.EOF
sSQL = "UPDATE Master_Child SET [AZ_CurrentOnhand]=" & myRecordSet![CurrentOnhand] & " WHERE Master_Child.AZ_Child='" & myRecordSet!Item & "'"
DoCmd.RunSQL (sSQL)
DoCmd.SetWarnings (False)
myRecordSet.MoveNext
Wend
DoCmd.SetWarnings True
End Function[/FONT]
Access takes about 25 minutes to run through this procedure and I know SQL could do it much quicker plus I could automate the update. Can anyone out there give me any ideas as to how to do something similar in SQL? I have a pretty advanced knowledge of Access, but more of a moderate to beginning level knowledge of SQL.
Thanks in advance for anyone's help!
Public Function UpdateAZOnhand()
Dim cnn1 As ADODB.Connection
Set cnn1 = CurrentProject.Connection
Dim myRecordSet As New ADODB.Recordset
myRecordSet.ActiveConnection = cnn1
Dim mySql As String
mySql = "SELECT AZ_Transactions.Item, Sum([AZ_Transactions.QTY]*IIf(Type='Credit',1,-1)) AS CurrentOnhand FROM AZ_Transactions GROUP BY AZ_Transactions.Item"
DoCmd.SetWarnings False
myRecordSet.Open (mySql)
While Not myRecordSet.EOF
sSQL = "UPDATE Master_Child SET [AZ_CurrentOnhand]=" & myRecordSet![CurrentOnhand] & " WHERE Master_Child.AZ_Child='" & myRecordSet!Item & "'"
DoCmd.RunSQL (sSQL)
DoCmd.SetWarnings (False)
myRecordSet.MoveNext
Wend
DoCmd.SetWarnings True
End Function[/FONT]