Ошибка: Неправильный синтаксис перед "0". - VB
Формулировка задачи:
Народ, что означает данная ошибка?
В VBA не силен, предупреждаю сразу....
Вот код:
__________________________________________________________________________________________________________________
Просьба: Не судите строго, я еще только начал учить VBA...
В VBA не силен, предупреждаю сразу....
Вот код:
Sub Macro1() Dim cSQLSrv As String Dim cSQLUsr As String Dim cSQLPwd As String Dim cSQLDB As String Dim cSQLWID As String Dim cSQLApp As String Dim cConStr As String Dim ProductCode As String Dim GroupeName As String Dim StartDateTime As String Dim FinishDateTime As String Dim TaskName As String Dim PartName As Object Dim iRow As Integer cSQLSrv = "\\\" cSQLUsr = "\\\" cSQLPwd = "\\\" cSQLDB = "\\\" cSQLWID = Application.UserName cSQLApp = Application.Name cConStr = "Provider = SQLOLEDB;" + _ "Password = " + cSQLPwd + ";" + _ "User ID=" + cSQLUsr + ";" + _ "Initial Catalog=" + cSQLDB + ";" + _ "Data Source=192.168.50.215;" Set oCon = CreateObject("ADODB.Connection") oCon.ConnectionString = cConStr oCon.Open Set oCon = CreateObject("ADODB.Connection") oCon.ConnectionString = cConStr oCon.Open Set oCmd = CreateObject("ADODB.Command") oCmd.ActiveConnection = oCon oCmd.CommandType = 1 oCmd.CommandText = "select TOP 5 TASK.TASKID,'' as Fio,Place.PlaceTechId as PlaceCode," oCmd.CommandText = oCmd.CommandText & " (case isnull(Part.ProductId,0) when 0 then Part.PartName else Product.ProductName end ) as PartName," & _ oCmd.CommandText = oCmd.CommandText & " TaskName From Task," & _ oCmd.CommandText = oCmd.CommandText & " Task.StartDateTime,Task.FinishDateTime,PT1.Shift as Shift1,PT2.Shift as Shift2," oCmd.CommandText = oCmd.CommandText & " isnull(Part.PartVolume,'') as Kol," oCmd.CommandText = oCmd.CommandText & " (case year(Task.StartDateTime) when year(GetDate()) then" oCmd.CommandText = oCmd.CommandText & " (case month(Task.StartDateTime) when month(GetDate()) then" oCmd.CommandText = oCmd.CommandText & " (case day(Task.StartDateTime) when day(GetDate()) then" oCmd.CommandText = oCmd.CommandText & " (case PT1.Shift when 1 then isnull(Part.PartVolume,0) else 0 end)" oCmd.CommandText = oCmd.CommandText & " else 0 end) else 0 end ) else 0 end) as Zap1," oCmd.CommandText = oCmd.CommandText & " (case year(Task.FinishDateTime) when year(GetDate()) then" oCmd.CommandText = oCmd.CommandText & " (case month(Task.FinishDateTime) when month(GetDate()) then" oCmd.CommandText = oCmd.CommandText & " (case day(Task.FinishDateTime) when day(GetDate()) then" oCmd.CommandText = oCmd.CommandText & " (case PT2.Shift when 1 then isnull(Part.PartVolume,0) else 0 end)" oCmd.CommandText = oCmd.CommandText & " else 0 end) else 0 end ) else 0 end) as Sd1," oCmd.CommandText = oCmd.CommandText & " (case year(Task.StartDateTime) when year(GetDate()) then" oCmd.CommandText = oCmd.CommandText & " (case month(Task.StartDateTime) when month(GetDate()) then" oCmd.CommandText = oCmd.CommandText & " (case day(Task.StartDateTime) when day(GetDate()) then" oCmd.CommandText = oCmd.CommandText & " (case PT1.Shift when 2 then isnull(Part.PartVolume,0) else 0 end)" oCmd.CommandText = oCmd.CommandText & " else 0 end) else 0 end ) else 0 end) as Zap2," oCmd.CommandText = oCmd.CommandText & " (case year(Task.FinishDateTime) when year(GetDate()) then" oCmd.CommandText = oCmd.CommandText & " (case month(Task.FinishDateTime) when month(GetDate()) then" oCmd.CommandText = oCmd.CommandText & " (case day(Task.FinishDateTime) when day(GetDate()) then" oCmd.CommandText = oCmd.CommandText & " (case PT2.Shift when 2 then isnull(Part.PartVolume,0) else 0 end)" oCmd.CommandText = oCmd.CommandText & " else 0 end) else 0 end ) else 0 end) as Sd2," oCmd.CommandText = oCmd.CommandText & " (case year(Task.StartDateTime) when year(GetDate()) then" oCmd.CommandText = oCmd.CommandText & " (case month(Task.StartDateTime) when month(GetDate()) then" oCmd.CommandText = oCmd.CommandText & " (case day(Task.StartDateTime) when day(GetDate()) then" oCmd.CommandText = oCmd.CommandText & " (case PT1.Shift when 3 then isnull(Part.PartVolume,0) else 0 end)" oCmd.CommandText = oCmd.CommandText & " else 0 end) else 0 end ) else 0 end) as Zap3," oCmd.CommandText = oCmd.CommandText & " (case year(Task.FinishDateTime) when year(GetDate()) then" oCmd.CommandText = oCmd.CommandText & " (case month(Task.FinishDateTime) when month(GetDate()) then" oCmd.CommandText = oCmd.CommandText & " (case day(Task.FinishDateTime) when day(GetDate()) then" oCmd.CommandText = oCmd.CommandText & " (case PT2.Shift when 3 then isnull(Part.PartVolume,0) else 0 end)" oCmd.CommandText = oCmd.CommandText & " else 0 end) else 0 end ) else 0 end) as Sd3" oCmd.CommandText = oCmd.CommandText & " Task.PartName+Task.TaskName as Naimenovanie" oCmd.CommandText = oCmd.CommandText & " from PlanTask AS Task" oCmd.CommandText = oCmd.CommandText & " left join PlanPart as Part on Task.PartId=Part.PartId" oCmd.CommandText = oCmd.CommandText & " left join PlanProduct as Product on Part.ProductId=Product.ProductId" oCmd.CommandText = oCmd.CommandText & " left join PlanPlace as Place on Task.PlaceId=Place.PlaceId" oCmd.CommandText = oCmd.CommandText & " left join PlanTime AS PT1 on Task.StartDateTime>PT1.StartDateTime and Task.StartDateTime<=PT1.FinishDateTime" oCmd.CommandText = oCmd.CommandText & " left join PlanTime AS PT2 on Task.FinishDateTime>PT2.StartDateTime and Task.FinishDateTime<=PT2.FinishDateTime" oCmd.CommandText = oCmd.CommandText & " where (Task.StateId Is Null Or Task.StateId = 30)" oCmd.CommandText = oCmd.CommandText & " and ((year(Task.StartDateTime)=year(GetDate())" oCmd.CommandText = oCmd.CommandText & " and month(Task.StartDateTime)=month(GetDate())" oCmd.CommandText = oCmd.CommandText & " and day(Task.StartDateTime)=day(GetDate()))" oCmd.CommandText = oCmd.CommandText & " or (year(Task.FinishDateTime)=year(GetDate())" oCmd.CommandText = oCmd.CommandText & " and month(Task.FinishDateTime)=month(GetDate())" oCmd.CommandText = oCmd.CommandText & " and day(Task.FinishDateTime)=day(GetDate())))" 'oCmd.CommandText = oCmd.CommandText & " and Task.TaskDescription like '%43-8%'" oCmd.CommandText = oCmd.CommandText & " and right(Task.TaskName,4)='_032'" oCmd.CommandText = oCmd.CommandText & " and Product.ProductName is not null" oCmd.CommandText = oCmd.CommandText & " ORDER BY Place.PlaceTechId,Task.StartDateTime,Task.FinishDateTime" Set oRec = oCmd.Execute MsgBox (oRec.State) Set oRec = CreateObject("ADODB.Recordset") oRec.Open oCmd.CommandText oRec.MoveFirst Do Until oRec.EOF MsgBox (oRec.Fields("Item").Value) oRec.MoveNext Loop Set oCmd = CreateObject("ADODB.Command") oCmd.ActiveConnection = oCon oCmd.CommandType = 1 oCmd.CommandText = oCmd.CommandText oCmd.Parameters.Refresh Set oRec = oCmd.Execute MsgBox (oRec.State) iRow = 0 SelectTaskField Row:=0, Column:="Îïåðàöèÿ" SetTaskField Field:="Îïåðàöèÿ", Value:="Task.PartName+Task.TaskName as Naimenovanie" SelectTaskField Row:=0, Column:="Íà÷àëî" SetTaskField Field:="Íà÷àëî", Value:="Zap1" SelectTaskField Row:=0, Column:="Îêîí÷àíèå" SetTaskField Field:="Îêîí÷àíèå", Value:="Zap2" SelectTaskField Row:=0, Column:="Íàçâàíèÿ ðåñóðñîâ" SetTaskField Field:="", Value:="Íàçâàíèÿ ðåñóðñî" SelectTaskField Row:=0, Column:="Ïðåäøåñòâåííèêè" SetTaskField Field:="Íàçâàíèÿ ðåñóðñîâ", Value:="" SelectTaskField Row:=0, Column:="Ïðåäøåñòâåííèêè" Set oCmd = Nothing Set oRec = Nothing Set oCon = Nothing Exit Sub For Each ADOErr In oCon.Errors MsgBox (Hex(ADOErr.Number) + " : " + ADOErr.Description) MsgBox (Hex(ADOErr.Number) + " : " + ADOErr.Description) Next End Sub
__________________________________________________________________________________________________________________
Просьба: Не судите строго, я еще только начал учить VBA...
Решение задачи: «Ошибка: Неправильный синтаксис перед "0".»
textual
Листинг программы
oCmd.CommandText = oCmd.CommandText & " (case isnull(Part.ProductId,0) when 0 then Part.PartName else Product.ProductName end ) as PartName," & _ " TaskName From Task," & _ " Task.StartDateTime,Task.FinishDateTime,PT1.Shift as Shift1,PT2.Shift as Shift2,"
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д