SQL Server:如何加入这两个表?

时间:2016-11-05 20:25:07

标签: sql sql-server tsql

你可以帮帮我吗?我正在尝试加入这两个表

Producto

+-------------+-------------+-------------------------------------------+----------------------+----------+-------+------------+-------+------------------------+----------+-------+-------+-------------------------------------------+----------------------+------------+-------+----------+----------+--------+--------+---------------+----------+------------+------------+---------------+---------------+--------+--------+------------------+---------+---------------+--------+------------+----------+------------+----------+-------------+------------+-------------------+-------------------+
| Id_Sucursal | Id_Producto |              Clave_Eq_Sisco               |      Num_Serie       | No_Parte |  OEM  | Cod_Barras | Marca |         Modelo         | Original | Linea | Nuevo |                Descr_Larga                |     Descr_Corta      | Existencia | Costo | Impuesto | Utilidad | Precio | Oferta | Precio_Oferta | Cantidad |  F_Inicio  |   F_Fin    | Precio_Maximo | Precio_Minimo | Maximo | Minimo | Compatibilidades | Estatus | Observaciones | Codigo |   F_Alta   | Usr_Alta |   F_Baja   | Usr_Baja | rendimiento | estatus_oc | porcentaje_maximo | porcentaje_minimo |
+-------------+-------------+-------------------------------------------+----------------------+----------+-------+------------+-------+------------------------+----------+-------+-------+-------------------------------------------+----------------------+------------+-------+----------+----------+--------+--------+---------------+----------+------------+------------+---------------+---------------+--------+--------+------------------+---------+---------------+--------+------------+----------+------------+----------+-------------+------------+-------------------+-------------------+
| CORDOBA     |        1219 | TORCSAMSAN0000001219                      | 28837                |          | 28837 | 28837      | SAMS  |                        | A        | TORC  | N     | TONER BOTELLA ALTERNO 220G                |                      |         43 |     0 |       16 |        0 |      0 | N      |             0 |        0 | 12/03/2013 | 12/03/2013 |             0 |             0 |      0 |      0 |                  | A       |               |        | 12/03/2013 | COMPRAS  | 01/01/1900 |          |        5000 |            |                 0 |                 0 |
| TEHUACAN    |        1219 | TORCSAMSAN0000001219                      | 28837                |          | 28837 | 28837      | SAMS  |                        | A        | TORC  | N     | TONER BOTELLA ALTERNO 220G                |                      |         31 |     0 |       16 |        0 |      0 | N      |             0 |        0 | 12/03/2013 | 12/03/2013 |             0 |             0 |      0 |      0 |                  | A       |               |        | 12/03/2013 | COMPRAS  | 01/01/1900 |          |        5000 |            |                 0 |                 0 |
| XALAPA      |        1219 | TORCSAMSAN0000001219                      | 28837                |          | 28837 | 28837      | SAMS  |                        | A        | TORC  | N     | TONER BOTELLA ALTERNO 220G                |                      |         10 |     0 |       16 |        0 |      0 | N      |             0 |        0 | 12/03/2013 | 12/03/2013 |             0 |             0 |      0 |      0 |                  | A       |               |        | 12/03/2013 | COMPRAS  | 01/01/1900 |          |        5000 |            |                 0 |                 0 |
| CORDOBA     |         612 | TORCHEPAAN0000000612                      | 32385                |          | 32385 | 32385      | HEPA  | LASER JET-1012         | A        | TORC  | N     | TONER RECARGA GENERICO  100 G HP          |                      |          1 |     0 |       16 |        0 |      0 | N      |             0 |        0 | 18/12/2012 | 18/12/2012 |             0 |             0 |      0 |      0 |                  | A       |               |        | 18/12/2012 | SUP      | 01/01/1900 |          |           0 |            |                 0 |                 0 |
| TEHUACAN    |         612 | TORCHEPAAN0000000612                      | 32385                |          | 32385 | 32385      | HEPA  | LASER JET-1012         | A        | TORC  | N     | TONER RECARGA GENERICO  100 G HP          |                      |          8 |     0 |       16 |        0 |      0 | N      |             0 |        0 | 18/12/2012 | 18/12/2012 |             0 |             0 |      0 |      0 |                  | A       |               |        | 18/12/2012 | SUP      | 01/01/1900 |          |           0 |            |                 0 |                 0 |
| XALAPA      |         612 | TORCHEPAAN0000000612                      | 32385                |          | 32385 | 32385      | HEPA  | LASER JET-1012         | A        | TORC  | N     | TONER RECARGA GENERICO  100 G HP          |                      |         11 |     0 |       16 |        0 |      0 | N      |             0 |        0 | 18/12/2012 | 18/12/2012 |             0 |             0 |      0 |      0 |                  | A       |               |        | 18/12/2012 | SUP      | 01/01/1900 |          |           0 |            |                 0 |                 0 |
| CORDOBA     |         717 | TORCKATUAN0000000717                      | 37069                | 37069    | 37069 | 37069      | SHAR  | AL-2031                | A        | TORC  | N     | TONER  RECARGA GENERICO  240 G  SHARP     |                      |          8 |     0 |       16 |        0 |      0 | N      |             0 |        0 | 20/12/2012 | 20/12/2012 |             0 |             0 |      0 |      0 |                  | A       |               |        | 20/12/2012 | SUP      | 01/01/1900 |          |        5000 |            |                 0 |                 0 |
| TEHUACAN    |         717 | TORCKATUAN0000000717                      | 37069                | 37069    | 37069 | 37069      | SHAR  | AL-2031                | A        | TORC  | N     | TONER  RECARGA GENERICO  240 G  SHARP     |                      |         15 |     0 |       16 |        0 |      0 | N      |             0 |        0 | 20/12/2012 | 20/12/2012 |             0 |             0 |      0 |      0 |                  | A       |               |        | 20/12/2012 | SUP      | 01/01/1900 |          |        5000 |            |                 0 |                 0 |
| XALAPA      |         717 | TORCKATUAN0000000717                      | 37069                | 37069    | 37069 | 37069      | SHAR  | AL-2031                | A        | TORC  | N     | TONER  RECARGA GENERICO  240 G  SHARP     |                      |         11 |     0 |       16 |        0 |      0 | N      |             0 |        0 | 20/12/2012 | 20/12/2012 |             0 |             0 |      0 |      0 |                  | A       |               |        | 20/12/2012 | SUP      | 01/01/1900 |          |        5000 |            |                 0 |                 0 |
| CORDOBA     |        1023 | TORCKATUAN0000001023                      | TK-1147-172--137-162 | 44259    | 44259 | 29458      | KYMI  |                        | A        | TORC  | N     | TONER  RECARGA GENERICO 290GR. KYOCERA    |                      |         19 |     0 |       16 |        0 |      0 | N      |             0 |        0 | 17/01/2013 | 17/01/2013 |             0 |             0 |      0 |      0 |                  | A       |               |        | 17/01/2013 | SUP      | 01/01/1900 |          |        7000 |            |                 0 |                 0 |
| TEHUACAN    |        1023 | TORCKATUAN0000001023                      | TK-1147-172--137-162 | 44259    | 44259 | 29458      | KYMI  |                        | A        | TORC  | N     | TONER  RECARGA GENERICO 290GR. KYOCERA    |                      |         27 |     0 |       16 |        0 |      0 | N      |             0 |        0 | 17/01/2013 | 17/01/2013 |             0 |             0 |      0 |      0 |                  | A       |               |        | 17/01/2013 | SUP      | 01/01/1900 |          |        7000 |            |                 0 |                 0 |
| XALAPA      |        1023 | TORCKATUAN0000001023                      | TK-1147-172--137-162 | 44259    | 44259 | 29458      | KYMI  |                        | A        | TORC  | N     | TONER  RECARGA GENERICO 290GR. KYOCERA    |                      |         18 |     0 |       16 |        0 |      0 | N      |             0 |        0 | 17/01/2013 | 17/01/2013 |             0 |             0 |      0 |      0 |                  | A       |               |        | 17/01/2013 | SUP      | 01/01/1900 |          |        7000 |            |                 0 |                 0 |
| CORDOBA     |        1803 | TINCHEPADESKJETADVANTAGE-2515ON0000001803 | # 662                | CZ103AL  |       | CZ103AL    | HEPA  | DESKJET ADVANTAGE-2515 | O        | TINC  | N     | CARTUCHO TINTA ORIGINAL HP NEGRO # 662    | CARTUCHO NEGRO #662  |          0 |     0 |       16 |        0 |      0 | N      |             0 |        0 | 08/02/2014 | 08/02/2014 |             0 |             0 |      0 |      0 |                  | A       |               |        | 08/02/2014 | COMPRAS  | 01/01/1900 |          |         100 |            |                 0 |                 0 |
| TEHUACAN    |        1803 | TINCHEPADESKJETADVANTAGE-2515ON0000001803 | # 662                | CZ103AL  |       | CZ103AL    | HEPA  | DESKJET ADVANTAGE-2515 | O        | TINC  | N     | CARTUCHO TINTA ORIGINAL HP NEGRO # 662    | CARTUCHO NEGRO #662  |          0 |     0 |       16 |        0 |      0 | N      |             0 |        0 | 08/02/2014 | 08/02/2014 |             0 |             0 |      0 |      0 |                  | A       |               |        | 08/02/2014 | COMPRAS  | 01/01/1900 |          |         100 |            |                 0 |                 0 |
| XALAPA      |        1803 | TINCHEPADESKJETADVANTAGE-2515ON0000001803 | # 662                | CZ103AL  |       | CZ103AL    | HEPA  | DESKJET ADVANTAGE-2515 | O        | TINC  | N     | CARTUCHO TINTA ORIGINAL HP NEGRO # 662    | CARTUCHO NEGRO #662  |          1 |     0 |       16 |        0 |      0 | N      |             0 |        0 | 08/02/2014 | 08/02/2014 |             0 |             0 |      0 |      0 |                  | A       |               |        | 08/02/2014 | COMPRAS  | 01/01/1900 |          |         100 |            |                 0 |                 0 |
| CORDOBA     |        1802 | TINCHEPADESKJETADVANTAGE-2515ON0000001802 | 662                  | CZ104AL  |       | CZ104AL    | HEPA  | DESKJET ADVANTAGE-2515 | O        | TINC  | N     | CARTUCHO TINTA ORIGINAL HP TRICOLOR # 662 | CARTUCHO # 662 TRICO |          0 |     0 |       16 |        0 |      0 | N      |             0 |        0 | 08/02/2014 | 08/02/2014 |             0 |             0 |      0 |      0 |                  | A       |               |        | 08/02/2014 | COMPRAS  | 01/01/1900 |          |         100 |            |                 0 |                 0 |
| TEHUACAN    |        1802 | TINCHEPADESKJETADVANTAGE-2515ON0000001802 | 662                  | CZ104AL  |       | CZ104AL    | HEPA  | DESKJET ADVANTAGE-2515 | O        | TINC  | N     | CARTUCHO TINTA ORIGINAL HP TRICOLOR # 662 | CARTUCHO # 662 TRICO |          0 |     0 |       16 |        0 |      0 | N      |             0 |        0 | 08/02/2014 | 08/02/2014 |             0 |             0 |      0 |      0 |                  | A       |               |        | 08/02/2014 | COMPRAS  | 01/01/1900 |          |         100 |            |                 0 |                 0 |
| XALAPA      |        1802 | TINCHEPADESKJETADVANTAGE-2515ON0000001802 | 662                  | CZ104AL  |       | CZ104AL    | HEPA  | DESKJET ADVANTAGE-2515 | O        | TINC  | N     | CARTUCHO TINTA ORIGINAL HP TRICOLOR # 662 | CARTUCHO # 662 TRICO |          1 |     0 |       16 |        0 |      0 | N      |             0 |        0 | 08/02/2014 | 08/02/2014 |             0 |             0 |      0 |      0 |                  | A       |               |        | 08/02/2014 | COMPRAS  | 01/01/1900 |          |         100 |            |                 0 |                 0 |
+-------------+-------------+-------------------------------------------+----------------------+----------+-------+------------+-------+------------------------+----------+-------+-------+-------------------------------------------+----------------------+------------+-------+----------+----------+--------+--------+---------------+----------+------------+------------+---------------+---------------+--------+--------+------------------+---------+---------------+--------+------------+----------+------------+----------+-------------+------------+-------------------+-------------------+

Kardex_Producto

+-------------+---------------+-----------------+----------------------+----------+-------+----------+-------+--------+--------+------------------+------------+------------+------------------+-------------+------------------+--------------+---------------+---------+------------+-------------+------------+------------+
    | Id_Sucursal | Id_Movimiento | Tipo_Movimiento |      Num_Serie       | No_Parte |  OEM  | Cantidad | Costo | Codigo | Oferta |    Ord_Compra    | No_Factura | Ord_Salida | No_Transferencia | No_Contrato |   No_Servicio    | Aut_Especial | Observaciones | Estatus | F_Entrada  | Usr_Entrada |  F_Salida  | Usr_Salida |
    +-------------+---------------+-----------------+----------------------+----------+-------+----------+-------+--------+--------+------------------+------------+------------+------------------+-------------+------------------+--------------+---------------+---------+------------+-------------+------------+------------+
    | XALAPA      |           504 | E+              | 28837                |          | 28837 |       10 |     0 |        | N      | Traspaso No. 543 |            |            |                  |             | Traspaso No. 543 |              |               | F       | 10/10/2016 | TCAXALGER   | 01/01/1900 |            |
    | XALAPA      |           504 | E+              | 32385                |          | 32385 |        5 |     0 |        | N      | Traspaso No. 543 |            |            |                  |             | Traspaso No. 543 |              |               | F       | 10/10/2016 | TCAXALGER   | 01/01/1900 |            |
    | XALAPA      |           504 | E+              | 37069                | 37069    | 37069 |       10 |     0 |        | N      | Traspaso No. 543 |            |            |                  |             | Traspaso No. 543 |              |               | F       | 10/10/2016 | TCAXALGER   | 01/01/1900 |            |
    | XALAPA      |           504 | E+              | TK-1147-172--137-162 | 44259    | 44259 |       10 |     0 |        | N      | Traspaso No. 543 |            |            |                  |             | Traspaso No. 543 |              |               | F       | 10/10/2016 | TCAXALGER   | 01/01/1900 |            |
    | XALAPA      |           505 | E+              | # 662                | CZ103AL  |       |        1 |     0 |        | N      | Traspaso No. 549 |            |            |                  |             | Traspaso No. 549 |              |               | F       | 13/10/2016 | TCAXALGER   | 01/01/1900 |            |
    | XALAPA      |           505 | E+              | 662                  | CZ104AL  |       |        1 |     0 |        | N      | Traspaso No. 549 |            |            |                  |             | Traspaso No. 549 |              |               | F       | 13/10/2016 | TCAXALGER   | 01/01/1900 |            |
    +-------------+---------------+-----------------+----------------------+----------+-------+----------+-------+--------+--------+------------------+------------+------------+------------------+-------------+------------------+--------------+---------------+---------+------------+-------------+------------+------------+

我正在尝试制作一份报告,向我展示,从表Kardex_Producto,Id_Sucursal,Id_Movimiento,Cantidad,Costo,Ord_Compra,而不是num_serie,或No_parte,或OEM,显示Producto的Descr_Larga。

我试过这句话:

SELECT 
    Producto.Descr_Larga, Kardex_Producto.Id_Sucursal, 
    Kardex_Producto.Id_Movimiento, Kardex_Producto.Cantidad, 
    Kardex_Producto.Costo, Kardex_Producto.Ord_Compra
FROM
    Kardex_Producto 
INNER JOIN
    Producto ON Kardex_Producto.No_Parte = Producto.No_Parte 
             AND Kardex_Producto.Id_Sucursal = 'xalapa'
WHERE 
   (Kardex_Producto.Id_Sucursal = 'xalapa' 
   AND Kardex_Producto.Id_Sucursal = Producto.Id_Sucursal) 
   AND (Kardex_Producto.F_Entrada >= CONVERT(DateTime, '20161001', 103)) 
        OR (Kardex_Producto.F_Salida  >= CONVERT(DateTime, '20161001', 103))

但它返回了错误的结果,如下所示:

+------------------------------------------------------+-------------+---------------+----------+-------+
|                     Descr_Larga                      | Id_Sucursal | Id_Movimiento | Cantidad | Costo |
+------------------------------------------------------+-------------+---------------+----------+-------+
| TONER CARTUCHO REMANOFACTURADO                       | XALAPA      |          1102 |        1 |     0 |
| TONER CARTUCHO REMANOFACTURADO                       | XALAPA      |          1104 |        1 |     0 |
| TONER CARTUCHO REMANOFACTURADO                       | XALAPA      |          1122 |        1 |     0 |
| TONER CARTUCHO REMANOFACTURADO                       | XALAPA      |          1125 |        1 |     0 |
| TONER CARTUCHO REMANOFACTURADO                       | XALAPA      |          1125 |        1 |     0 |
| TONER CARTUCHO REMANOFACTURADO                       | XALAPA      |          1133 |        1 |     0 |
| TONER CARTUCHO REMANOFACTURADO                       | XALAPA      |          1146 |        1 |     0 |
| TONER CARTUCHO REMANOFACTURADO                       | XALAPA      |          1146 |        1 |     0 |
| TONER CARTUCHO REMANOFACTURADO                       | XALAPA      |          1147 |        1 |     0 |
| TONER CARTUCHO REMANOFACTURADO                       | XALAPA      |          1134 |        1 |     0 |
| TONER CARTUCHO REMANOFACTURADO                       | XALAPA      |          1138 |        1 |     0 |
| TONER CARTUCHO REMANOFACTURADO                       | XALAPA      |          1141 |        1 |     0 |
| TONER CARTUCHO REMANOFACTURADO                       | XALAPA      |          1142 |        1 |     0 |
| TONER CARTUCHO REMANOFACTURADO                       | XALAPA      |          1144 |        1 |     0 |
| TONER CARTUCHO REMANOFACTURADO                       | XALAPA      |          1145 |        2 |     0 |
| TONER CARTUCHO  GENERICO EQUIVALENTE A TN-850  HP    | XALAPA      |          1102 |        1 |     0 |
| TONER CARTUCHO  GENERICO EQUIVALENTE A TN-850  HP    | XALAPA      |          1104 |        1 |     0 |
| TONER CARTUCHO  GENERICO EQUIVALENTE A TN-850  HP    | XALAPA      |          1122 |        1 |     0 |
| TONER CARTUCHO  GENERICO EQUIVALENTE A TN-850  HP    | XALAPA      |          1125 |        1 |     0 |
| TONER CARTUCHO  GENERICO EQUIVALENTE A TN-850  HP    | XALAPA      |          1125 |        1 |     0 |
| TONER CARTUCHO  GENERICO EQUIVALENTE A TN-850  HP    | XALAPA      |          1133 |        1 |     0 |
| TONER CARTUCHO  GENERICO EQUIVALENTE A TN-850  HP    | XALAPA      |          1146 |        1 |     0 |
| TONER CARTUCHO  GENERICO EQUIVALENTE A TN-850  HP    | XALAPA      |          1146 |        1 |     0 |
| TONER CARTUCHO  GENERICO EQUIVALENTE A TN-850  HP    | XALAPA      |          1147 |        1 |     0 |
| TONER CARTUCHO  GENERICO EQUIVALENTE A TN-850  HP    | XALAPA      |          1134 |        1 |     0 |
| TONER CARTUCHO  GENERICO EQUIVALENTE A TN-850  HP    | XALAPA      |          1138 |        1 |     0 |
| TONER CARTUCHO  GENERICO EQUIVALENTE A TN-850  HP    | XALAPA      |          1141 |        1 |     0 |
| TONER CARTUCHO  GENERICO EQUIVALENTE A TN-850  HP    | XALAPA      |          1142 |        1 |     0 |
| TONER CARTUCHO  GENERICO EQUIVALENTE A TN-850  HP    | XALAPA      |          1144 |        1 |     0 |
| TONER CARTUCHO  GENERICO EQUIVALENTE A TN-850  HP    | XALAPA      |          1145 |        2 |     0 |
| BALERO DE RODILLO DE PRESION                         | XALAPA      |          1102 |        1 |     0 |
| BALERO DE RODILLO DE PRESION                         | XALAPA      |          1104 |        1 |     0 |
| BALERO DE RODILLO DE PRESION                         | XALAPA      |          1122 |        1 |     0 |
| BALERO DE RODILLO DE PRESION                         | XALAPA      |          1125 |        1 |     0 |
| BALERO DE RODILLO DE PRESION                         | XALAPA      |          1125 |        1 |     0 |
| BALERO DE RODILLO DE PRESION                         | XALAPA      |          1133 |        1 |     0 |
| BALERO DE RODILLO DE PRESION                         | XALAPA      |          1146 |        1 |     0 |
| BALERO DE RODILLO DE PRESION                         | XALAPA      |          1146 |        1 |     0 |
| BALERO DE RODILLO DE PRESION                         | XALAPA      |          1147 |        1 |     0 |
| BALERO DE RODILLO DE PRESION                         | XALAPA      |          1134 |        1 |     0 |
| BALERO DE RODILLO DE PRESION                         | XALAPA      |          1138 |        1 |     0 |
| BALERO DE RODILLO DE PRESION                         | XALAPA      |          1141 |        1 |     0 |
| BALERO DE RODILLO DE PRESION                         | XALAPA      |          1142 |        1 |     0 |
| BALERO DE RODILLO DE PRESION                         | XALAPA      |          1144 |        1 |     0 |
| BALERO DE RODILLO DE PRESION                         | XALAPA      |          1145 |        2 |     0 |
| CHIP CARTUCHO XEROX 013R00601                        | XALAPA      |          1102 |        1 |     0 |
| CHIP CARTUCHO XEROX 013R00601                        | XALAPA      |          1104 |        1 |     0 |
| CHIP CARTUCHO XEROX 013R00601                        | XALAPA      |          1122 |        1 |     0 |
| CHIP CARTUCHO XEROX 013R00601                        | XALAPA      |          1125 |        1 |     0 |
| CHIP CARTUCHO XEROX 013R00601                        | XALAPA      |          1125 |        1 |     0 |
| CHIP CARTUCHO XEROX 013R00601                        | XALAPA      |          1133 |        1 |     0 |
| CHIP CARTUCHO XEROX 013R00601                        | XALAPA      |          1146 |        1 |     0 |
| CHIP CARTUCHO XEROX 013R00601                        | XALAPA      |          1146 |        1 |     0 |
| CHIP CARTUCHO XEROX 013R00601                        | XALAPA      |          1147 |        1 |     0 |
| CHIP CARTUCHO XEROX 013R00601                        | XALAPA      |          1134 |        1 |     0 |
| CHIP CARTUCHO XEROX 013R00601                        | XALAPA      |          1138 |        1 |     0 |
| CHIP CARTUCHO XEROX 013R00601                        | XALAPA      |          1141 |        1 |     0 |
| CHIP CARTUCHO XEROX 013R00601                        | XALAPA      |          1142 |        1 |     0 |
| CHIP CARTUCHO XEROX 013R00601                        | XALAPA      |          1144 |        1 |     0 |
| CHIP CARTUCHO XEROX 013R00601                        | XALAPA      |          1145 |        2 |     0 |
| LAMINA ALTERNO CANON IR-1600                         | XALAPA      |          1102 |        1 |     0 |
| LAMINA ALTERNO CANON IR-1600                         | XALAPA      |          1104 |        1 |     0 |
| LAMINA ALTERNO CANON IR-1600                         | XALAPA      |          1122 |        1 |     0 |
| LAMINA ALTERNO CANON IR-1600                         | XALAPA      |          1125 |        1 |     0 |
| LAMINA ALTERNO CANON IR-1600                         | XALAPA      |          1125 |        1 |     0 |
| LAMINA ALTERNO CANON IR-1600                         | XALAPA      |          1133 |        1 |     0 |
| LAMINA ALTERNO CANON IR-1600                         | XALAPA      |          1146 |        1 |     0 |
| LAMINA ALTERNO CANON IR-1600                         | XALAPA      |          1146 |        1 |     0 |
| LAMINA ALTERNO CANON IR-1600                         | XALAPA      |          1147 |        1 |     0 |
| LAMINA ALTERNO CANON IR-1600                         | XALAPA      |          1134 |        1 |     0 |
| LAMINA ALTERNO CANON IR-1600                         | XALAPA      |          1138 |        1 |     0 |
| LAMINA ALTERNO CANON IR-1600                         | XALAPA      |          1141 |        1 |     0 |
| LAMINA ALTERNO CANON IR-1600                         | XALAPA      |          1142 |        1 |     0 |
| LAMINA ALTERNO CANON IR-1600                         | XALAPA      |          1144 |        1 |     0 |
| LAMINA ALTERNO CANON IR-1600                         | XALAPA      |          1145 |        2 |     0 |
| TONER HP RECARGA  COLOR NEGRO 55 GRS CHIP INCLUIDO   | XALAPA      |          1102 |        1 |     0 |
| TONER HP RECARGA  COLOR NEGRO 55 GRS CHIP INCLUIDO   | XALAPA      |          1104 |        1 |     0 |
| TONER HP RECARGA  COLOR NEGRO 55 GRS CHIP INCLUIDO   | XALAPA      |          1122 |        1 |     0 |
| TONER HP RECARGA  COLOR NEGRO 55 GRS CHIP INCLUIDO   | XALAPA      |          1125 |        1 |     0 |
| TONER HP RECARGA  COLOR NEGRO 55 GRS CHIP INCLUIDO   | XALAPA      |          1125 |        1 |     0 |
| TONER HP RECARGA  COLOR NEGRO 55 GRS CHIP INCLUIDO   | XALAPA      |          1133 |        1 |     0 |
| TONER HP RECARGA  COLOR NEGRO 55 GRS CHIP INCLUIDO   | XALAPA      |          1146 |        1 |     0 |
| TONER HP RECARGA  COLOR NEGRO 55 GRS CHIP INCLUIDO   | XALAPA      |          1146 |        1 |     0 |
| TONER HP RECARGA  COLOR NEGRO 55 GRS CHIP INCLUIDO   | XALAPA      |          1147 |        1 |     0 |
| TONER HP RECARGA  COLOR NEGRO 55 GRS CHIP INCLUIDO   | XALAPA      |          1134 |        1 |     0 |
| TONER HP RECARGA  COLOR NEGRO 55 GRS CHIP INCLUIDO   | XALAPA      |          1138 |        1 |     0 |
| TONER HP RECARGA  COLOR NEGRO 55 GRS CHIP INCLUIDO   | XALAPA      |          1141 |        1 |     0 |
| TONER HP RECARGA  COLOR NEGRO 55 GRS CHIP INCLUIDO   | XALAPA      |          1142 |        1 |     0 |
| TONER HP RECARGA  COLOR NEGRO 55 GRS CHIP INCLUIDO   | XALAPA      |          1144 |        1 |     0 |
| TONER HP RECARGA  COLOR NEGRO 55 GRS CHIP INCLUIDO   | XALAPA      |          1145 |        2 |     0 |
+------------------------------------------------------+-------------+---------------+----------+-------+

结果应该是

    +----------------------+-------------------------------------------+-------------+---------------+----------+--------+------------------+------------+------------+
|      Num_Serie       |                Descr_Larga                | Id_Sucursal | Id_Movimiento | Cantidad | Costo  |    Ord_Compra    | F_Entrada  |  F_Salida  |
+----------------------+-------------------------------------------+-------------+---------------+----------+--------+------------------+------------+------------+
| 28837                | TONER BOTELLA ALTERNO 220G                | Xalapa      |           504 |       10 | 398    | Traspaso No. 543 | 10/10/2016 | 01/01/1900 |
| 32385                | TONER RECARGA GENERICO  100 G HP          | Xalapa      |           504 |        5 | 130    | Traspaso No. 543 | 10/10/2016 | 01/01/1900 |
| 37069                | TONER  RECARGA GENERICO  240 G  SHARP     | Xalapa      |           504 |       10 | 230    | Traspaso No. 543 | 10/10/2016 | 01/01/1900 |
| TK-1147-172--137-162 | TONER  RECARGA GENERICO 290GR. KYOCERA    | Xalapa      |           504 |       10 | 398    | Traspaso No. 543 | 10/10/2016 | 01/01/1900 |
| # 662                | CARTUCHO TINTA ORIGINAL HP NEGRO # 662    | Xalapa      |           505 |        1 | 185.76 | Traspaso No. 549 | 13/10/2016 | 01/01/1900 |
| 662                  | CARTUCHO TINTA ORIGINAL HP TRICOLOR # 662 | Xalapa      |           505 |        1 | 185.76 | Traspaso No. 549 | 13/10/2016 | 01/01/1900 |
+----------------------+-------------------------------------------+-------------+---------------+----------+--------+------------------+------------+------------+

但它反复提供信息,我不知道还有什么可以尝试的。 任何帮助都将非常感激。

提前谢谢!

1 个答案:

答案 0 :(得分:0)

但是Kardex_Producto.No_Parte为空,所以这不会起作用 您需要决定加入什么,并且您可能需要更多数据

我打赌你的意思是这个

SELECT Distinct 
       Producto.Descr_Larga, Kardex_Producto.Id_Sucursal, 
       Kardex_Producto.Id_Movimiento, Kardex_Producto.Cantidad, 
       Kardex_Producto.Costo, Kardex_Producto.Ord_Compra
FROM   Kardex_Producto 
JOIN   Producto 
         ON Kardex_Producto.No_Parte = Producto.No_Parte 
        and Kardex_Producto.Id_Sucursal = 'xalapa'
        and Kardex_Producto.Id_Sucursal = Producto.Id_Sucursal
WHERE (   Kardex_Producto.F_Entrada >= CONVERT(DateTime, '20161001', 103) 
       OR Kardex_Producto.F_Salida  >= CONVERT(DateTime, '20161001', 103)
      )