is this normal? I can't click anything in my form when I'm exporting a data to XML from 14k records? And I think my form freeze. I'm using vb.net in exporting file from database. Hope to hear positive response.
CODE :
Using xmlWriter As XmlWriter = xmlWriter.Create(oFileName, xmlSetting)
xmlWriter.WriteStartDocument()
xmlWriter.WriteStartElement("Products")
xmlWriter.WriteAttributeString("type", "array")
oDotNet.SqlDb.strCommand = "SELECT IsNULL(SuppCatNum, '') [Stock No], " & _
" ItemCode, " & _
" IsNULL(CodeBars, '') [BardCode List], " & _
" IsNULL(FrgnName, '') [FrgnName], " & _
" ItemName, " & _
" IsNULL(InvntryUom, '') [InvntryUom], " & _
" b.ItmsGrpCod [Category Code], " & _
" b.ItmsGrpNam [Category Name], " & _
" a.QryGroup1 [Allow Decimal], " & _
" Vat.Rate, " & _
" a.ManSerNum, " & _
" IsNULL(a.CardCode, '-1') [CardCode]" & _
" FROM OITM a" & _
" INNER JOIN OITB b ON a.ItmsGrpCod = b.ItmsGrpCod " & _
" INNER JOIN OVTG Vat ON a.VatGourpSa = Vat.Code " '& _
'" WHERE ItemCode = 'Davies EL-0020 White'"
ts_Progress.Maximum = oDotNet.SqlDb.Ds.Tables(0).DefaultView.Count
For i As Integer = 0 To oDotNet.SqlDb.Ds.Tables(0).DefaultView.Count - 1
xmlWriter.WriteStartElement("Product")
xmlWriter.WriteElementString("id", -1)
xmlWriter.WriteElementString("stock_no", oDotNet.SqlDb.GetField(i, "Stock No"))
xmlWriter.WriteElementString("reference", oDotNet.SqlDb.GetField(i, "ItemCode"))
xmlWriter.WriteElementString("name", oDotNet.SqlDb.GetField(i, "ItemName"))
xmlWriter.WriteElementString("short_name", oDotNet.SqlDb.GetField(i, "FrgnName"))
xmlWriter.WriteElementString("supplier_code", oDotNet.SqlDb.GetField(i, "CardCode"))
'*BardCode*'
Select Case oType
Case 1
Dim _BardCode As String = Nothing
oSql.strCommand = "SELECT BcdCode FROM OBCD bcd INNER JOIN OUOM uom ON bcd.UomEntry = uom.UomEntry " & _
" WHERE ItemCode = '" & oDotNet.SqlDb.GetField(i, "ItemCode") & "' AND bcd.BcdCode != '" & oDotNet.SqlDb.GetField(i, "BardCode List") & "' " & _
" /*AND uom.UomCode = '" & oDotNet.SqlDb.GetField(i, "InvntryUom") & "'*/ "
If oSql.Ds.Tables(0).DefaultView.Count > 0 Then
For oBardCode As Integer = 0 To oSql.Ds.Tables(0).DefaultView.Count - 1
_BardCode &= oSql.GetField(oBardCode).ToString & ", "
Next
_BardCode = oDotNet.SqlDb.GetField(i, "BardCode List") & ", " & _BardCode.Substring(0, _BardCode.Length - 2)
Else
_BardCode = oDotNet.SqlDb.GetField(i, "BardCode List")
End If
xmlWriter.WriteElementString("barcode_list", _BardCode)
xmlWriter.WriteElementString("category_id", -1)
xmlWriter.WriteElementString("unit_name", oDotNet.SqlDb.GetField(i, "InvntryUom")) 'oDotNet.SqlDb.GetField(i, "InvntryUom"))
xmlWriter.WriteElementString("retail_price", "")
'*WhsCode Here*'
Dim _WhsCode As String = Nothing
oSql.strCommand = "SELECT WhsCode FROM OITW WHERE ItemCode = '" & oDotNet.SqlDb.GetField(i, "ItemCode") & "' "
For oWhsCode As Integer = 0 To oSql.Ds.Tables(0).DefaultView.Count - 1
_WhsCode &= oSql.GetField(oWhsCode).ToString & ", "
Next
_WhsCode = _WhsCode.Substring(0, _WhsCode.Length - 2)
End Select
xmlWriter.WriteEndElement()
ts_Value += 1
ts_Progress.Value = ts_Value
Next
xmlWriter.WriteEndElement()
xmlWriter.WriteEndDocument()
End Using
You could try Application.DoEvents this is a very sloppy but easy fix to your problem. It will allow you to use the form still, but it will be very slow.
Related
I'm trying to pass the results of an array into a subroutine. I have an array that picks up four different Buyer codes from a list. They're labelled as BuyOne, BuyTwo, BuyThree, BuyFour. I'm trying to get the results into the next subroutine, but I'm getting a type mismatch at the subroutine call. Even when I fiddle with it I don't know how to get the results into the subroutine. Can anyone tell me what i'm doing wrong?
Code below:
lastRow = Range("O" & Rows.Count).End(xlUp).Row
Set rBuyerList = Range("O1:O" & lastRow)
arrBuyer = Array("BuyOne", "BuyTwo", "BuyThree", "BuyFour")
For i = 0 To UBound(arrBuyer)
With Application
chkFind = .IfError(.Match(Range(arrBuyer(i)), Range("O1:O50"), 0), 0)
End With
If Range(arrBuyer(i)) = vbNullString Or chkFind = False Then
MsgBox "Invalid Buyer Code.." & arrBuyer(i)
Range(arrBuyer(i)).Select
End If
Next i
Call runFinished(sFrDt, sToDt, arrBuyer())
Sheets("Main Sheet").Select
MsgBox ("done...")
End Sub
Sub runFinished(sFrDt As String, sToDt As String, arrBuyer() As Variant)
Dim SQL As String
' add a new work sheet
ActiveWorkbook.Worksheets.Add
' dispay Criteria
Cells(1, 1) = "Run Date: " & Now()
Call MergeLeft("A1:B1")
Cells(2, 1) = "Criteria:"
Cells(2, 2) = "From " & Range("reqFrDT") & " -To- " & Range("reqToDt")
' SQL
SQL = "select a.StockCode [Finished Part], a.QtyToMake, FQOH,FQOO,/*FQIT,*/FQOA, b.Component [Base Material], CQOH,CQOO,CQIT,CQOA " & _
"from ( " & _
" SELECT StockCode, sum(QtyToMake) QtyToMake " & _
" from [MrpSugJobMaster] " & _
" WHERE 1 = 1 " & _
" AND JobStartDate >= '" & sFrDt & "' " & _
" AND JobStartDate <= '" & sToDt & "' " & _
" AND JobClassification = 'OUTS' " & _
" AND ReqPlnFlag <> 'I' AND Source <> 'E' Group BY StockCode " & _
" ) a " & _
"LEFT JOIN BomStructure b on a.StockCode = b.ParentPart " & _
"LEFT JOIN ( " & _
" select StockCode, sum(QtyOnHand) FQOH, Sum(QtyAllocated) FQOO, Sum(QtyInTransit) FQIT, Sum(QtyOnOrder) FQOA " & _
" from InvWarehouse " & _
" where Warehouse in ('01','DS','RM') " & _
" group by StockCode " & _
") c on a.StockCode = c.StockCode " & _
"LEFT JOIN ( " & _
" select StockCode, sum(QtyOnHand) CQOH, Sum(QtyAllocated) CQOO, Sum(QtyInTransit) CQIT, Sum(QtyOnOrder) CQOA " & _
" from InvWarehouse " & _
" where Warehouse in ('01','DS','RM') " & _
" group by StockCode " & _
") d on b.Component = d.StockCode "
SQL = SQL & _
"LEFT JOIN InvMaster e on a.StockCode = e.StockCode " & _
"WHERE 1 = 1 " & _
"and e.Buyer in ('" & BuyOne & "','" & BuyTwo & "','" & BuyThree & "','" & BuyFour & "') " & _
"ORDER BY a.StockCode "
If you have this line in your code
arrBuyer = Array("BuyOne", "BuyTwo", "BuyThree", "BuyFour")
Proper call should be
Call runFinished(sFrDt, sToDt, arrBuyer)
And proper declaration of the function is
Sub runFinished(sFrDt As String, sToDt As String, arrBuyer As Variant) without ()
Edit (Thanks to #Rory)
Previously stated is true if arrBuyer was not declared as follows: dim arrBuyer() as variant or dim arrBuyer(). On the other hand if declaration was dim arrBuyer() 'as variant OP's code would work w/o any changes.
Final note: I still prefer not using arrBuyer() As Variant in the sub declaration.
Below is the code. What I'm confused about is how to get the BuyOne, BuyTwo, BuyThree, BuyFour array (arrBuyer) to allow blank entries. Right now if an entry is blank it'll say it's an invalid entry, whereas I just want it skipped over. In addition, if ALL entries are blank, I want it where the code just assumes the user wants to run every possible entry.
The user enters codes into four specific slots on the left of the page as seen in the image. Currently the code checks a list off to the right of the page to see if values match. How do I go about doing the above?
If Range("reqFrDt") = vbNullString Or IsDate(Range("reqFrDt")) = False Then
MsgBox "From date missing..."
Range("reqFrDt").Select
End
Else
sFrDt = Range("reqFrDt")
End If
If Range("reqToDt") = vbNullString Or IsDate(Range("reqToDt")) = False Then
MsgBox "To date missing or invalid.."
Range("reqToDt").Select
End
Else
sToDt = Range("reqToDt")
End If
lastRow = Range("O" & Rows.Count).End(xlUp).Row
Set rBuyerList = Range("O1:O" & lastRow)
arrBuyer = Array("BuyOne", "BuyTwo", "BuyThree", "BuyFour")
For i = 0 To UBound(arrBuyer)
With Application
chkFind = .IfError(.Match(Range(arrBuyer(i)), Range("O1:O50"), 0), 0)
End With
If Range(arrBuyer(i)) = vbNullString Or chkFind = False Then
MsgBox "Invalid Buyer Code.." & arrBuyer(i)
Range(arrBuyer(i)).Select
End If
Next i
Call runFinished(sFrDt, sToDt, arrBuyer)
Sheets("Main Sheet").Select
MsgBox ("done...")
End Sub
Sub runFinished(sFrDt As String, sToDt As String, arrBuyer As Variant)
Dim SQL As String
' add a new work sheet
ActiveWorkbook.Worksheets.Add
' dispay Criteria
Cells(1, 1) = "Run Date: " & Now()
Call MergeLeft("A1:B1")
Cells(2, 1) = "Criteria:"
Cells(2, 2) = "From " & Range("reqFrDT") & " -To- " & Range("reqToDt")
' SQL
SQL = "select a.StockCode [Finished Part], a.QtyToMake, FQOH,FQOO,/*FQIT,*/FQOA, b.Component [Base Material], CQOH,CQOO,CQIT,CQOA " & _
"from ( " & _
" SELECT StockCode, sum(QtyToMake) QtyToMake " & _
" from [MrpSugJobMaster] " & _
" WHERE 1 = 1 " & _
" AND JobStartDate >= '" & sFrDt & "' " & _
" AND JobStartDate <= '" & sToDt & "' " & _
" AND JobClassification = 'OUTS' " & _
" AND ReqPlnFlag <> 'I' AND Source <> 'E' Group BY StockCode " & _
" ) a " & _
"LEFT JOIN BomStructure b on a.StockCode = b.ParentPart " & _
"LEFT JOIN ( " & _
" select StockCode, sum(QtyOnHand) FQOH, Sum(QtyAllocated) FQOO, Sum(QtyInTransit) FQIT, Sum(QtyOnOrder) FQOA " & _
" from InvWarehouse " & _
" where Warehouse in ('01','DS','RM') " & _
" group by StockCode " & _
") c on a.StockCode = c.StockCode " & _
"LEFT JOIN ( " & _
" select StockCode, sum(QtyOnHand) CQOH, Sum(QtyAllocated) CQOO, Sum(QtyInTransit) CQIT, Sum(QtyOnOrder) CQOA " & _
" from InvWarehouse " & _
" where Warehouse in ('01','DS','RM') " & _
" group by StockCode " & _
") d on b.Component = d.StockCode "
SQL = SQL & _
"LEFT JOIN InvMaster e on a.StockCode = e.StockCode " & _
"WHERE 1 = 1 " & _
"and e.Buyer in ('" & Range(arrBuyer(0)) & "','" & Range(arrBuyer(1)) & "','" & Range(arrBuyer(2)) & "','" & Range(arrBuyer(3)) & "') " & _
"ORDER BY a.StockCode "
I am trying to execute this following query in SQL Server and it gives me the following errors:
Msg 156, Level 15, State 1, Line 5
Incorrect syntax near the keyword 'FROM'.
Msg 102, Level 15, State 1, Line 122
Incorrect syntax near 'CompanyCode'.
Also, when running it in VS2008, I get these errors:
Incorrect syntax near the keyword 'from'.
Incorrect syntax near 'a'.
Incorrect syntax near 'b'.
This is the code:
Using SearchDS As New DataSet
Using objDBcommand As New DBCommand
objDBcommand.CommandText = " select a.*, isNull(b.CalculationType,0) as CalculationType, " & _
" isnull(b.amountCode,0) as AmountCode, isNull(b.AmountDescription, '') as AmountDescription " & _
" INTO " & strBasetable & _
" from( " objDBcommand.CommandText = " select a.*, isNull(b.CalculationType,0) as CalculationType, " & _
" isnull(b.amountCode,0) as AmountCode, isNull(b.AmountDescription, '') as AmountDescription " & _
" INTO " & strBasetable & _
" from( "
objDBcommand.CommandText &= " select isnull(VEE.TotalDelaysDuration,0) as TotalDays, isnull(VEE.TCE,0 ) as NetProfitEstimated, Comp.CompanyCode, Comp.Description as CompanyDescription, b.AccountCode, b.AccountDescription, " & _
" case " & _
" when (b.AmountDebitBC - b.AmountCreditBC) > 0 then (b.AmountDebitBC - b.AmountCreditBC) " & _
" else " & clsGlobals.NU(0) & _
" end as AmountDebitBC, " & _
" case " & _
" when (b.AmountDebitBC - b.AmountCreditBC) < 0 then (b.AmountDebitBC - b.AmountCreditBC) " & _
" else " & clsGlobals.NU(0) & _
" end as AmountCreditBC, " & _
" Voy.CharterPartyDate, Voy.VoyageCode, Voy.Description,Voy.TimeCharterInd, Voy.StartDateTime, Voy.LastVoyageTerminationDateTime, H.LastHireDateTime, " & _
" CASE when Voy.TimeCharterInd = " & clsGlobals.NU(1) & " then Voy.Hire " & _
" else case when Voy.TimeCharterInd = " & clsGlobals.NU(0) & " then " & _
" case when voy.FreightRate <> " & clsGlobals.NU(0) & " then voy.FreightRate " & _
" else case when voy.TotalFreight <> " & clsGlobals.NU(0) & " then voy.TotalFreight " & _
" else " & clsGlobals.NU(0) & _
" End " & _
" End " & _
" End " & _
" end as Hire, " & _
" case when Voy.TimeCharterInd = " & clsGlobals.NU(0) & " then " & _
" case when voy.FreightRate <> " & clsGlobals.NU(0) & " then " & clsGlobals.NU(1) & _
" else case when voy.TotalFreight <> " & clsGlobals.NU(0) & " then " & clsGlobals.NU(2) & _
" else " & clsGlobals.NU(0) & _
" End " & _
" End " & _
" else " & clsGlobals.NU(0) & _
" end ValueFreight, " & _
" Voy.Commission, voy.ActualEndDateTime, " & _
" BP.Name, " & _
" case " & _
" when Voy.lastVoyageTerminationDateTime <> " & clsGlobals.Q(clsGlobals.AD(clsGlobals.gMINDATE)) & " then (CAST(Voy.StartDateTime AS NUMERIC(9,2)) - CAST(Voy.lastVoyageTerminationDateTime AS NUMERIC(9,2))) " & _
" else 0 " & _
" end " & _
" AS BallastDays, " & _
" isnull( case " & _
" when voy.ActualEndDateTime <> " & clsGlobals.Q(clsGlobals.AD(clsGlobals.gMINDATE)) & " then voy.ActualEndDateTime " & _
" when voy.EstimatedEndDateTime <> " & clsGlobals.Q(clsGlobals.AD(clsGlobals.gMINDATE)) & " then voy.EstimatedEndDateTime " & _
" End , 0) as TerminatedDate, " & _
" case " & _
" when voy.ActualEndDateTime <> " & clsGlobals.Q(clsGlobals.AD(clsGlobals.gMINDATE)) & " then " & clsGlobals.NU(0) & _
" when voy.EstimatedEndDateTime <> " & clsGlobals.Q(clsGlobals.AD(clsGlobals.gMINDATE)) & " then " & clsGlobals.NU(1) & _
" End as ActualOrEstimated, " & _
" CASE when Voy.TimeCharterInd = 1.0 then " & _
" case when voy.ActualEndDateTime = " & clsGlobals.Q(clsGlobals.AD(clsGlobals.gMINDATE)) & _
" then " & _
" Case when H.LastHireDateTime <> " & clsGlobals.Q(clsGlobals.AD(clsGlobals.gMINDATE)) & _
" then CAST(H.LastHireDateTime AS NUMERIC(9,2)) - CAST(Voy.StartDateTime AS NUMERIC(9,2)) " & _
" Else " & clsGlobals.NU(0) & " End " & _
" else " & _
" CAST(voy.ActualEndDateTime AS NUMERIC(9,2)) - CAST(Voy.StartDateTime AS NUMERIC(9,2)) " & _
" End " & _
" else " & _
" case when voy.ActualEndDateTime <> " & clsGlobals.Q(clsGlobals.AD(clsGlobals.gMINDATE)) & " then " & _
" CAST(Voy.ActualEndDateTime AS NUMERIC(9,2)) - CAST(Voy.StartDateTime AS NUMERIC(9,2))" & _
" else " & _
" case when voy.EstimatedEndDateTime <> " & clsGlobals.Q(clsGlobals.AD(clsGlobals.gMINDATE)) & " then " & _
" CAST(voy.EstimatedEndDateTime AS NUMERIC(9,2)) - CAST(voy.StartDateTime AS NUMERIC(9,2))" & _
" Else " & _
clsGlobals.NU(0) & _
" End " & _
" End " & _
" end as 'Voyage Period', " & _
" Case " & _
" when Voy.TimeCharterInd = " & clsGlobals.NU(1) & " AND H.LastHireDateTime <> " & clsGlobals.Q(clsGlobals.AD(clsGlobals.gMINDATE)) & _
" Then CAST(H.LastHireDateTime AS NUMERIC(9,2)) - CAST(lastVoyageTerminationDateTime AS NUMERIC(9,2)) " & _
" Else " & clsGlobals.NU(0) & _
" end as 'Hire Collected' " & _
" FROM voyages voy left outer join VoyagesEstimationHeader VEE on VEE.VoyageCode = voy.Voyagecode and VEE.VesselCode = voy.Vesselcode and VEE.EstimationStatus = '3' " & _
" AND VEE.PrevailingInd = (Case when ((select count(*) from VoyagesEstimationHeader where vesselcode = VEE.VesselCode and VoyageCode = VEE.VoyageCode AND EstimationStatus = '3') > 1 ) then 1 " & _
" else (select PrevailingInd from VoyagesEstimationHeader where vesselcode = VEE.VesselCode and VoyageCode = VEE.VoyageCode AND EstimationStatus = '3') end ) " & _
" LEFT OUTER JOIN BusinessPartners BP ON Voy.ChartererCode = BP.BusinessPartnerCode, " & clsFunctions.GetActualTableName(Me.Name, "Companies") & " Comp, " & _
" ( " & _
" select Fid.AccountCode, Acc.Description as AccountDescription, FID.SubAccountCode, FID.CompanyCode, " & _
" sum( Fid.AmountDebitBC)as 'AmountDebitBC', sum(Fid.AmountCreditBC) as 'AmountCreditBC' " & _
" from FiStatementsDetail FID, FiStatementsHeader FIH, " & clsFunctions.GetActualTableName(Me.Name, "Accounts_1") & " Acc, " & _
clsFunctions.GetActualTableName(Me.Name, "Companies") & " Companies " & _
" where Fid.AccountCode = acc.AccountCode " & _
" And Acc.SubAccountType = " & enmSubAccountType.enmVoyage & _
" AND Fid.TransactionType = FiH.TransactionType" & _
" AND Fid.TransactionNum = FiH.TransactionNum " & _
" AND Fid.FiscalYear = FiH.FiscalYear " & _
" AND FiH.TransactionReasonCode NOT IN ( " & strExcludeTransactionReasons & ")" & _
" AND FID.CompanyCode = Companies.CompanyCode "
If dtpDateFrom.Checked = True Then
objDBcommand.CommandText &= " AND FIH.TransactionDate >= " & clsGlobals.Q(clsGlobals.AD(dtpDateFrom.Value.Date))
End If
If dtpDateTo.Checked = True Then
objDBcommand.CommandText &= " AND FIH.TransactionDate <= " & clsGlobals.Q(clsGlobals.AD(dtpDateTo.Value.Date))
End If
objDBcommand.CommandText &= " group by Fid.AccountCode, Acc.Description, FID.SubAccountCode, FID.CompanyCode " & _
" ) b, " & _
" ( select max(fid.Hiredate)as LastHireDateTime ,Fid.subAccountCode, FID.CompanyCode " & _
" FROM fistatementsDetail fid, " & _
clsFunctions.GetActualTableName(Me.Name, "Companies") & " Companies " & _
" WHERE fid.CompanyCode = Companies.CompanyCode "
If Not strSelectedCompanies.Equals(String.Empty) Then
objDBcommand.CommandText &= " AND fid.companycode IN ( " & strSelectedCompanies & ")"
End If
objDBcommand.CommandText &= " GROUP BY FID.CompanyCode, Fid.subAccountCode " & _
" ) H " & _
" where Voy.Voyagecode = b.SubAccountCode " & _
" AND b.CompanyCode = Voy.Vesselcode " & _
" AND voy.VesselCode = Comp.Companycode " & _
" AND voy.VesselCode = H.Companycode " & _
" AND H.SubAccountCode = b.SubAccountCode "
If Not strSelectedCompanies.Equals(String.Empty) Then
objDBcommand.CommandText &= " AND voy.VesselCode IN ( " & strSelectedCompanies & ")"
End If
If Not txtVoyage.CodeText.Equals(String.Empty) OrElse txtVoyage.cboSelectedItems.DataSource IsNot Nothing Then
objDBcommand.CommandText &= " AND Voy.VoyageCode"
If Not txtVoyage.CodeText.Equals(String.Empty) Then
objDBcommand.CommandText &= " = " & clsGlobals.Q(txtVoyage.CodeText)
Else
objDBcommand.CommandText &= " IN " & clsFunctions.CriteriaValuesFromRowsCollection(CType(txtVoyage.cboSelectedItems.DataSource, DataSet).Tables(0).Rows, txtVoyage.CodeFieldName)
End If
End If
objDBcommand.CommandText &= ")a left outer Join " & _
"( " & _
" select case " & _
" when Links.CalculationType = 1 then 0 " & _
" when Links.CalculationType = 2 then 1 " & _
" else -1 " & _
" end as TimeCharterInd, " & _
" Links.CalculationType, Links.amountCode, Links.AmountDescription, Links.AccountCode " & _
" FROM " & _
"( " & _
" select AL.AmountCode , S.AmountDescription , AL.AccountCode,Al.CalculationType " & _
" from sea_VoyageEstimationAmounts s, ActualLinks AL " & _
" where al.AmountCode = s.AmountCode " & _
" )Links " & _
" )b on a.TimeCharterInd = b.TimecharterInd " & _
" and a.AccountCode = b.AccountCode " & _
" order by a.companyCode, a.AccountCode "
objDBcommand.Execute(SearchDS)
Here is the SQL part:
SELECT a.*,
isNull(b.CalculationType, 0) AS CalculationType,
isnull(b.amountCode, 0) AS AmountCode,
isNull(b.AmountDescription, '') AS AmountDescription INTO
FROM (
SELECT isnull(VEE.TotalDelaysDuration, 0) AS TotalDays,
isnull(VEE.TCE, 0) AS NetProfitEstimated,
Comp.CompanyCode,
Comp.Description AS CompanyDescription,
b.AccountCode,
b.AccountDescription,
CASE
WHEN (b.AmountDebitBC - b.AmountCreditBC) > 0 THEN (b.AmountDebitBC - b.AmountCreditBC)
ELSE 0
END AS AmountDebitBC,
CASE
WHEN (b.AmountDebitBC - b.AmountCreditBC) < 0 THEN (b.AmountDebitBC - b.AmountCreditBC)
ELSE 0
END AS AmountCreditBC,
Voy.CharterPartyDate,
Voy.VoyageCode,
Voy.Description,
Voy.TimeCharterInd,
Voy.StartDateTime,
Voy.LastVoyageTerminationDateTime,
H.LastHireDateTime,
CASE
WHEN Voy.TimeCharterInd = 1 THEN Voy.Hire
ELSE CASE
WHEN Voy.TimeCharterInd = 0 THEN CASE
WHEN voy.FreightRate <> 0 THEN voy.FreightRate
ELSE CASE
WHEN voy.TotalFreight <> 0 THEN voy.TotalFreight
ELSE 0
END
END
END
END AS Hire,
CASE
WHEN Voy.TimeCharterInd = 0 THEN CASE
WHEN voy.FreightRate <> 0 THEN 1
ELSE CASE
WHEN voy.TotalFreight <> 0 THEN 2
ELSE 0
END
END
ELSE 0
END ValueFreight,
Voy.Commission,
voy.ActualEndDateTime,
BP.Name,
CASE
WHEN Voy.lastVoyageTerminationDateTime <> '1900-01-01 00:00:00' THEN (CAST(Voy.StartDateTime AS NUMERIC(9, 2)) - CAST(Voy.lastVoyageTerminationDateTime AS NUMERIC(9, 2)))
ELSE 0
END AS BallastDays,
isnull(CASE
WHEN voy.ActualEndDateTime <> '1900-01-01 00:00:00' THEN voy.ActualEndDateTime
WHEN voy.EstimatedEndDateTime <> '1900-01-01 00:00:00' THEN voy.EstimatedEndDateTime
END, 0) AS TerminatedDate,
CASE
WHEN voy.ActualEndDateTime <> '1900-01-01 00:00:00' THEN 0
WHEN voy.EstimatedEndDateTime <> '1900-01-01 00:00:00' THEN 1
END AS ActualOrEstimated,
CASE
WHEN Voy.TimeCharterInd = 1.0 THEN CASE
WHEN voy.ActualEndDateTime = '1900-01-01 00:00:00' THEN CASE
WHEN H.LastHireDateTime <> '1900-01-01 00:00:00' THEN CAST(H.LastHireDateTime AS NUMERIC(9, 2)) - CAST(Voy.StartDateTime AS NUMERIC(9, 2))
ELSE 0
END
ELSE CAST(voy.ActualEndDateTime AS NUMERIC(9, 2)) - CAST(Voy.StartDateTime AS NUMERIC(9, 2))
END
ELSE CASE
WHEN voy.ActualEndDateTime <> '1900-01-01 00:00:00' THEN CAST(Voy.ActualEndDateTime AS NUMERIC(9, 2)) - CAST(Voy.StartDateTime AS NUMERIC(9, 2))
ELSE CASE
WHEN voy.EstimatedEndDateTime <> '1900-01-01 00:00:00' THEN CAST(voy.EstimatedEndDateTime AS NUMERIC(9, 2)) - CAST(voy.StartDateTime AS NUMERIC(9, 2))
ELSE 0
END
END
END AS 'Voyage Period',
CASE
WHEN Voy.TimeCharterInd = 1
AND H.LastHireDateTime <> '1900-01-01 00:00:00' THEN CAST(H.LastHireDateTime AS NUMERIC(9, 2)) - CAST(lastVoyageTerminationDateTime AS NUMERIC(9, 2))
ELSE 0
END AS 'Hire Collected'
FROM voyages voy
LEFT OUTER JOIN VoyagesEstimationHeader VEE ON VEE.VoyageCode = voy.Voyagecode
AND VEE.VesselCode = voy.Vesselcode
AND VEE.EstimationStatus = '3'
AND VEE.PrevailingInd = (CASE
WHEN (
(SELECT count(*)
FROM VoyagesEstimationHeader
WHERE vesselcode = VEE.VesselCode
AND VoyageCode = VEE.VoyageCode
AND EstimationStatus = '3') > 1) THEN 1
ELSE
(SELECT PrevailingInd
FROM VoyagesEstimationHeader
WHERE vesselcode = VEE.VesselCode
AND VoyageCode = VEE.VoyageCode
AND EstimationStatus = '3')
END)
LEFT OUTER JOIN BusinessPartners BP ON Voy.ChartererCode = BP.BusinessPartnerCode,
Companies Comp, (
SELECT Fid.AccountCode,
Acc.Description AS AccountDescription,
FID.SubAccountCode,
FID.CompanyCode,
sum(Fid.AmountDebitBC)AS 'AmountDebitBC',
sum(Fid.AmountCreditBC) AS 'AmountCreditBC'
FROM FiStatementsDetail FID,
FiStatementsHeader FIH,
Accounts Acc,
Companies Companies
WHERE Fid.AccountCode = acc.AccountCode
AND Acc.SubAccountType = 2
AND Fid.TransactionType = FiH.TransactionType
AND Fid.TransactionNum = FiH.TransactionNum
AND Fid.FiscalYear = FiH.FiscalYear
AND FiH.TransactionReasonCode NOT IN ('YP',
'YC')
AND FID.CompanyCode = Companies.CompanyCode
I have a set of data that I upload to SQL and since a couple of new columns have been added (abandoned IVR & answered IVR) it is failing to upload properly.
The data will now only land in the temp table and not the full data one, but what makes it all the more confusing is that it's saying their is a syntax error of ',' on the bottom line which is blank
This is my merge statement which is when I debug is saying where the potential error is. But I don't understand why the error is pointing at a blank row and stopping the upload from happening?
Could anyone give me any pointers, apologies for the code layout - I don't know how to set it out.
Thanks
Dan
sSQL = "MERGE [C3 ODS].Telephony AS Target USING (SELECT CallDate,VDN,VDN_Name,Skill,Skill_Name,Telephony_Lookup,Site,Team,SubTeam,Client, '" & _
" Scheme,Calls_Offered,Calls_Answered,Calls_Abandoned,Calls_Abandoned_SLA,Calls_Answered_SLA,Average_TalkTime,Average_ACW,Average_HandleTime, '" & _
" Average_AbandonTime,Average_SpeedAnswer,TelephonySystem,TimePeriod1,TimePeriod2,TimePeriod3,TimePeriod4,TimePeriod5,TimePeriod6,TimePeriod7, '" & _
" TimePeriod8,TimePeriod9,Abandon1,Abandon2,Abandon3,Abandon4,Abandon5,Abandon6,Abandon7,Abandon8,Abandon9,Abandon10,Answered1,Answered2, '" & _
" Answered3,Answered4,Answered5,Answered6,Answered7,Answered8,Answered9,Answered10,DataLoad_Date,ClientGroup,LOB,ServiceLevel,Section, '" & _
" ForecastGroup,AbandonedIVR,AnsweredIVR FROM [C3 ODS].Telephony_Temp) AS Temp " & _
" ON Target.CallDate = Temp.CallDate AND Target.Telephony_Lookup = Temp.Telephony_Lookup WHEN MATCHED THEN UPDATE SET Target.Calls_Offered = Temp.Calls_Offered, '" & _
" Target.Calls_Answered = Temp.Calls_Answered, Target.Calls_Abandoned = Temp.Calls_Abandoned, Target.Calls_Abandoned_SLA = Temp.Calls_Abandoned_SLA, '" & _
" Target.Calls_Answered_SLA = Temp.Calls_Answered_SLA, Target.Average_TalkTime = Temp.Average_TalkTime, Target.Average_ACW = Temp.Average_ACW, '" & _
" Target.Average_HandleTime = Temp.Average_HandleTime, Target.Average_AbandonTime = Temp.Average_AbandonTime, Target.Average_SpeedAnswer = Temp.Average_SpeedAnswer, '" & _
" Target.VDN_Name = Temp.VDN_Name, Target.Skill_Name = Temp.Skill_Name, Target.Site = Temp.Site, Target.Team = Temp.Team, Target.SubTeam = Temp.SubTeam, '" & _
" Target.ClientGroup = Temp.ClientGroup, Target.Client = Temp.Client, Target.Scheme = Temp.Scheme " & _
" WHEN NOT MATCHED THEN INSERT (CallDate,VDN,VDN_Name,Skill,Skill_Name,Telephony_Lookup,Site,Team,SubTeam,Client,Scheme,Calls_Offered,Calls_Answered, '" & _
" Calls_Abandoned,Calls_Abandoned_SLA,Calls_Answered_SLA,Average_TalkTime,Average_ACW,Average_HandleTime,Average_AbandonTime,Average_SpeedAnswer, '" & _
" TelephonySystem,TimePeriod1,TimePeriod2,TimePeriod3,TimePeriod4,TimePeriod5,TimePeriod6,TimePeriod7,TimePeriod8,TimePeriod9,Abandon1,Abandon2, '" & _
" Abandon3,Abandon4,Abandon5,Abandon6,Abandon7,Abandon8,Abandon9,Abandon10,Answered1,Answered2,Answered3,Answered4,Answered5,Answered6,Answered7, '" & _
" Answered8,Answered9,Answered10,DataLoad_Date,ClientGroup,LOB,ServiceLevel,Section,ForecastGroup,AbandonedIVR,AnsweredIVR) " & _
" VALUES (Temp.CallDate, Temp.VDN, Temp.VDN_Name, Temp.Skill, Temp.Skill_Name, Temp.Telephony_Lookup, Temp.Site, Temp.Team, Temp.SubTeam, '" & _
" Temp.Client, Temp.Scheme, Temp.Calls_Offered, Temp.Calls_Answered, Temp.Calls_Abandoned, Temp.Calls_Abandoned_SLA, Temp.Calls_Answered_SLA, '" & _
" Temp.Average_TalkTime, Temp.Average_ACW, Temp.Average_HandleTime, Temp.Average_AbandonTime, Temp.Average_SpeedAnswer, Temp.TelephonySystem, '" & _
" Temp.TimePeriod1, Temp.TimePeriod2, Temp.TimePeriod3, Temp.TimePeriod4, Temp.TimePeriod5, Temp.TimePeriod6, Temp.TimePeriod7, Temp.TimePeriod8, '" & _
" Temp.TimePeriod9, Temp.Abandon1, Temp.Abandon2, Temp.Abandon3, Temp.Abandon4, Temp.Abandon5, Temp.Abandon6, Temp.Abandon7, Temp.Abandon8, '" & _
" Temp.Abandon9, Temp.Abandon10, Temp.Answered1, Temp.Answered2, Temp.Answered3, Temp.Answered4, Temp.Answered5, Temp.Answered6, Temp.Answered7, '" & _
" Temp.Answered8, Temp.Answered9, Temp.Answered10, Temp.DataLoad_Date, Temp.ClientGroup, Temp.LOB, Temp.ServiceLevel, Temp.Section, '" & _
" Temp.ForecastGroup, Temp.AbandonedIVR, Temp.AnsweredIVR);"
Cn.Execute sSQL
I have done a bit of work on my code, and still unsure about how some of the code needs to be done in order to work.
So far I got a function named FunctionUp' coded, this is the code that will go in the following sequence:
If array of orders contains:
'A1G722
'A1G723
'A1G724
'A1G725
'A1G726
'A1G727
I added a reference to the current location as a query-string parameter named rowindex, so if the order passed in query-string is 'A1G725', the row index value will be 4, then function code will ideally browse in this sequence: 'A1G725', 'A1G724', 'A1G723', 'A1G722'
The code for the button:
.Write "<input type='submit' name='btnUp' value='Next' class='buttonRight' />"
The code that calls the function:
If Request("btnUp") = "Next" Then Call FuctionUp()
The code for the function:
Function FuctionUp()
Dim objConn
Dim objRS
Dim SQLOrderList
Dim SQLCurrentOrder
Dim currentorder
Dim previousorder
Dim sortby
Dim dtstart
Dim dtend
Dim index
currentorder = Trim(Request.QueryString("order"))
sortby = Request.QueryString("sortby")
currentorder = Request.QueryString("order")
dtstart = Request.QueryString("start")
dtend = Request.QueryString("end")
Set objRS = Server.CreateObject("ADODB.Recordset")
Set objConn = CreateObject("ADODB.Connection")
objConn.Open Application("conn_AWDSTAGE")
objRS.Cursortype = 3
SQLOrderList = "SELECT orderno" & _
" FROM _order" & _
" WHERE order_date >= '" & dtstart & "'" & _
" AND order_date < '" & dtend & "'" & _
" ORDER BY " & sortby
objRS.Open SQLOrderList, objConn
index = CINT(Request.QueryString("rowindex"))
If Not isNumeric(index) Or index = "" Then
index = 0
End If
'Get this to Array.
Dim iArray
Dim i
Dim sizeOfiArray
iArray = objRS.GetRows()
' sample of array contents after sql execution
'A1G722
'A1G723
'A1G724
'A1G725
'A1G726
'A1G727
sizeOfiArray = uBound(iArray) + 1
if not index >= (sizeOfiArray - 1) then previousorder = (index + 1)
If Not previousorder Is Nothing Then
Response.Redirect("~/printpreview.asp?order=" & previousorder(i) &
"&site=" & spiderSiteKey &
"&env=" & strEnv &
"&start=" & CDate(dtstart) &
"&end=" & CDate(dtend) &
"&rowindex=" & (index + 1) &
"&sortby=" & sortby)
Else
Response.Redirect("~/printpreview.asp?order=" & currentOrder.OrderID &
"&site=" & spiderSiteKey &
"&env=" & strEnv &
"&start=" & CDate(dtstart)) &
"&end=" & CDate(dtend) &
"&rowindex=" & (index) &
"&sortby=" & strSortBy &
"&LastRecord=Up")
End If
objRS.Close()
Set objRS = Nothing
objConn.Close()
Set objConn = Nothing
End Function
Wouldn't it be easier simply to get the next or previous orders directly from the database using SQL:
sSQLGetPrevOrder = "SELECT top(1) PREV.* " _
& " FROM [Order] PREV " _
& " JOIN ( " _
& " SELECT " & strOrderBy & " sortvalue, orderno " _
& " FROM Order WHERE orderno='" & strCurrentOrder & "' " _
& " ) CURR " _
& " ON PREV." & strOrderBy & " < CURR.sortvalue " _
& " OR ( PREV." & strOrderBy & " = CURR.sortvalue " _
& " AND PREV.orderno < CURR.orderno ) " _
& " ORDER BY PREV." & strOrderBy & " DESC, PREV.orderno DESC "
sSQLGetNextOrder = "SELECT top(1) NXT.* " _
& " FROM [Order] NXT " _
& " JOIN ( " _
& " SELECT " & strOrderBy & " sortvalue, orderno " _
& " FROM Order WHERE orderno='" & strCurrentOrder & "' " _
& " ) CURR " _
& " ON NXT." & strOrderBy & " > CURR.sortvalue " _
& " OR ( NXT." & strOrderBy & " = CURR.sortvalue " _
& " AND NXT.orderno > CURR.orderno ) " _
& " ORDER BY NXT." & strOrderBy & " ASC, NXT.orderno ASC "
(Apologies if this code has syntax errors, I have not been able to test it)
If orderno is always a number, you could omit the quote marks around strCurrentOrder.