Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql rk.交叉选项卡使用数据具有列。我没有用那个。这真的是对导入到另一个系统的非规范化。哇,正是我所需要的。非常感谢你。 Create table tmp ( plant int, material vchar(20), workcenter in_Sql_Ms Access - Fatal编程技术网

Sql rk.交叉选项卡使用数据具有列。我没有用那个。这真的是对导入到另一个系统的非规范化。哇,正是我所需要的。非常感谢你。 Create table tmp ( plant int, material vchar(20), workcenter in

Sql rk.交叉选项卡使用数据具有列。我没有用那个。这真的是对导入到另一个系统的非规范化。哇,正是我所需要的。非常感谢你。 Create table tmp ( plant int, material vchar(20), workcenter in,sql,ms-access,Sql,Ms Access,rk.交叉选项卡使用数据具有列。我没有用那个。这真的是对导入到另一个系统的非规范化。哇,正是我所需要的。非常感谢你。 Create table tmp ( plant int, material vchar(20), workcenter int, setuptime vchar(20) ) insert into tmp values( 1, mat1, 2, 30) insert into tmp values( 1, mat1, 3, 30) insert into tm


rk.交叉选项卡使用数据具有列。我没有用那个。这真的是对导入到另一个系统的非规范化。哇,正是我所需要的。非常感谢你。
Create table tmp
(
  plant int,
  material vchar(20),
  workcenter int,
  setuptime vchar(20)
)

insert into tmp values( 1, mat1, 2, 30)
insert into tmp values( 1, mat1, 3, 30)
insert into tmp values( 1, mat2, 3, 30)
insert into tmp values( 1, mat2, 4, 30)
insert into tmp values( 2, mat1, 4, 30)
insert into tmp values( 2, mat1, 5, 30)
Plant  Material  Workcenter1  Setuptime1  Workcenter2  Setuptime2
1      Mat1      2            30          3            30
1      Mat2      3            30          4            30
2      Mat1      4            30          5            30
SELECT t.Plant, 
    t.Material, 
    t.Workcenter as Workcenter1, 
    t.setuptime as SetupTime1
    t2.Workcenter as Workcenter2, 
    t2.setuptime as SetupTime2
FROM tmp t
LEFT JOIN tmp t2
  on t.plant = t2.plant
  and t.material = t2.material
Plant  Material  Workcenter1  Setuptime1  Workcenter2  Setuptime2
1      Mat1      2            30          2            30
1      Mat1      2            30          3            30
1      Mat1      3            30          2            30
1      Mat1      3            30          3            30
1      Mat2      3            30          4            30
1      Mat2      3            30          3            30
1      Mat2      4            30          3            30
1      Mat2      4            30          4            30
2      Mat1      4            30          5            30
2      Mat1      4            30          4            30
2      Mat1      5            30          5            30
2      Mat1      5            30          4            30
Create table tmp
(
  plant int,
  material vchar(20),
  workcenter int,
  setuptime vchar(20),
  myCol int
);
insert into tmp values( 1, mat1, 2, 30, 1);
insert into tmp values( 1, mat1, 3, 30, 2);
insert into tmp values( 1, mat2, 2, 30, 1);
insert into tmp values( 1, mat2, 3, 30, 2);
insert into tmp values( 2, mat1, 4, 30, 1);
insert into tmp values( 2, mat1, 5, 30, 2);

SELECT tmp.plant, tmp.material, tmp.workcenter,   tmp.setuptime,
                                tmp_1.workcenter, tmp_1.setuptime
FROM tmp INNER JOIN tmp AS tmp_1 ON (tmp.material = tmp_1.material)
    AND (tmp.plant = tmp_1.plant)
WHERE   (((tmp.myCol)=1)
    AND ((tmp_1.myCol)=2));
Plant | Mat  | Wkcntr1 | STime1 | Wkcntr2 | STime2 
1     | Mat1 | 2       | 30     | 3       | 30 
1     | Mat2 | 3       | 30     | 4       | 30 
2     | Mat1 | 4       | 30     | 5       | 30 
SELECT tmp.plant, tmp.material, tmp.workcenter AS W1, tmp.setuptime AS S1, tmp_1.workcenter AS W2, tmp_1.setuptime AS S2
FROM tmp INNER JOIN tmp AS tmp_1 ON (tmp.material = tmp_1.material) AND (tmp.plant = tmp_1.plant)
WHERE (((tmp.recordNum)=1) AND ((tmp_1.recordNum)=2));
ExpandTable
Public Sub ExpandTable()

    Dim db As DAO.Database
    Dim rs As DAO.Recordset, rs2 As DAO.Recordset
    Dim td As DAO.TableDef
    Dim fd As DAO.Field
    Dim maxWorkCenters As Integer
    Dim i As Integer
    Dim sql As String

    Set db = CurrentDb

    ' Delete the old result table if there was one '
    On Error Resume Next
    db.TableDefs.Delete "result"
    On Error GoTo 0

    ' Create the result table '
    Set td = db.CreateTableDef("result")
    td.Fields.Append td.CreateField("Plant", dbInteger)
    td.Fields.Append td.CreateField("Material", dbText)
    ' Get the maximum number of workcenters we will need '
    ' for a given Plan/Material combination '
    sql = "SELECT Count(*) FROM Temp GROUP BY Plant, Material"
    Set rs = db.OpenRecordset(sql, dbOpenSnapshot)
    maxWorkCenters = Nz(rs.Fields(0).Value, 0)
    rs.Close
    Set rs = Nothing
    ' Create as many columns as we need to fit all these combinations '
    For i = 1 To maxWorkCenters
        td.Fields.Append td.CreateField("WorkCenter" & i, dbText)
        td.Fields.Append td.CreateField("SetupTime" & i, dbInteger)
    Next i
    db.TableDefs.Append td

    ' Now get the data into the new table '
    Dim lastPlant As Variant, lastMaterial As Variant
    Dim curcol As Integer
    sql = "SELECT Plant, Material, Workcenter, Setuptime FROM Temp ORDER BY Plant, Material, WorkCenter"
    Set rs = db.OpenRecordset(sql, dbOpenSnapshot)
    Set rs2 = db.OpenRecordset("result", dbOpenDynaset)
    With rs
        lastPlant = 0
        lastMaterial = ""
        Do While Not .EOF
            If (Nz(!Plant) <> lastPlant) Or (Nz(!Material) <> lastMaterial) Then
                If rs2.EditMode = dbEditAdd Then
                    ' Save the previously edited record if any '
                    rs2.Update
                End If

                ' Different plant/material, so we add a new result '
                rs2.AddNew
                rs2!Plant = !Plant
                rs2!Material = !Material
                rs2!WorkCenter1 = !WorkCenter
                rs2!SetupTime1 = !Setuptime
                lastPlant = Nz(!Plant)
                lastMaterial = Nz(!Material)
                curcol = 1
            Else
                ' Same plant/material combi, so we fill the next column set '
                curcol = curcol + 1
                rs2.Fields("Workcenter" & curcol).Value = !WorkCenter
                rs2.Fields("SetupTime" & curcol).Value = !Setuptime
            End If
            .MoveNext
        Loop
        If rs2.EditMode = dbEditAdd Then
            ' Save the last result '
            rs2.Update
        End If
    End With

    Set rs2 = Nothing
    Set rs = Nothing
    Set db = Nothing

End Sub