INNER JOIN PROALPES..CUSTOMER ALID02 ON (ALID02.CUST_CODE=ALID01.CUSTP_CODE)
StrJoin = strJoin & "INNER JOIN PROALPES..INVPAY ALID03 ON (ALID03.INV_FILE=ALID01.INV_FILE AND ALID03.INV_NUM=ALID01.INV_NUM)"
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionSELECT ALID01.INV_FILE, ALID01.INV_NUM, ALID01.CUST_REF, ALID01.ORDERSOU, ALID01.CREAC_DATE, ALID01.MARK_CODE, ALID01.CUSTP_CODE, ALID02.ACC_CODE, ALID01.SP_CODE, ALID01.TTC_AMOUNT, ALID03.PAY_AMOUNT, ALID01.AMOUNT_SIGN, ALID01.DATE_DUE,(ALID02.AUT_OVERD+ALID02.AUT_SFAC), ALID02.CUST_PHONE, ALID02.CUST_FAX, ALID02.SIREN_CODE, ALID01.REL1_DATE, ALID01.REL2_DATE, ALID01.REL3_DATE, ALID01.BRANC_CODE, ALID01.CUST_CODE, ALID01.ESRC_FILE, ALID01.RC_NUM, ALID08.NBPAY_DAY, ALID18.SIT_NAME, ALID09.SP_CODE, ALID09.SP_NAME, ALID01.OFF_FILE, ALID01.OFF_NUM, ALID02.ACCOL_CODE, ALID02.INV_NAME,(SELECT COUNT(ALID19.PAY_NUM) FROM PROALPES..PAYDETUNPAID ALID19 WHERE ALID19.INV_FILE=ALID01.INV_FILE AND ALID19.INV_NUM=ALID01.INV_NUM) FROM PROALPES..INREFER ALID01 INNER JOIN PROALPES..CUSTOMER ALID02 ON (ALID02.CUST_CODE=ALID01.CUSTP_CODE) INNER JOIN PROALPES..INVPAY ALID03 ON (ALID03.INV_FILE=ALID01.INV_FILE AND ALID03.INV_NUM=ALID01.INV_NUM) INNER JOIN PROALPES..CUSTTYPE ALID07 ON (ALID07.CUSTY_CODE=ALID02.CUSTY_CODE) INNER JOIN PROALPES..PAYMENT ALID08 ON (ALID08.PAY_CODE=ALID01.PAY_CODE) INNER JOIN PROALPES..SALESMEN ALID09 ON (ALID09.SP_CODE=ALID01.SP_CODE) LEFT OUTER JOIN PROALPES..CUSTOMDB ALID12 ON (ALID12.CUST_CODE=ALID01.CUSTP_CODE AND ALID12.BRANC_CODE=ALID01.BRANC_CODE) LEFT OUTER JOIN PROALPES..CUSTTYPE ALID17 ON (ALID17.CUSTY_CODE=ALID12.CUSTY_CODE) LEFT OUTER JOIN PROALPES..CONTRACT ALID18 ON (ALID18.ESRC_FILE=ALID01.ESRC_FILE AND ALID18.RC_NUM=ALID01.RC_NUM) WHERE ALID01.DOC_STATUS<>5 AND ALID01.FLAG_CONSO=2 AND ( ALID01.FLAG_PAY=1) AND ALID01.TTC_AMOUNT<>0 AND ( ((ALID12.CUSTY_CODE IS NULL OR ALID12.CUSTY_CODE='') AND (ALID07.FACTOR_TYP<>1 OR ALID07.FACTOR_TYP IS NULL)) OR (ALID12.CUSTY_CODE IS NOT NULL AND ALID12.CUSTY_CODE<>'' AND (ALID17.FACTOR_TYP<>1 OR ALID17.FACTOR_TYP IS NULL)))
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:= _ "OLEDB;DSN=proalpes;UID=Administrateur;;APP=Microsoft Office 2003;WSID=GFPCORDIRPO01;DATABASE=PROALPES;" _ , Destination:=Range("$B$1")).QueryTable .CommandType = xlCmdSql strSelect = "SELECT ALID01.INV_FILE, ALID01.INV_NUM, ALID01.CUST_REF, ALID01.ORDERSOU, ALID01.CREAC_DATE, ALID01.MARK_CODE, ALID01.CUSTP_CODE, ALID02.ACC_CODE, ALID01.SP_CODE, ALID01.TTC_AMOUNT, ALID03.PAY_AMOUNT, ALID01.AMOUNT_SIGN, ALID01.DATE_DUE,(ALID02.AUT_OVERD+ALID02.AUT_SFAC), ALID02.CUST_PHONE, ALID02.CUST_FAX, ALID02.SIREN_CODE, ALID01.REL1_DATE, ALID01.REL2_DATE, ALID01.REL3_DATE, ALID01.BRANC_CODE, ALID01.CUST_CODE, ALID01.ESRC_FILE, ALID01.RC_NUM, ALID08.NBPAY_DAY, ALID18.SIT_NAME, ALID09.SP_CODE, ALID09.SP_NAME, ALID01.OFF_FILE, ALID01.OFF_NUM, ALID02.ACCOL_CODE, ALID02.INV_NAME,(SELECT COUNT(ALID19.PAY_NUM)" strFrom = "FROM PROALPES..PAYDETUNPAID ALID19" strWhere = "WHERE ALID19.INV_FILE=ALID01.INV_FILE AND ALID19.INV_NUM=ALID01.INV_NUM)" strFrom = "FROM PROALPES..INREFER ALID01" strJoin = "INNER JOIN PROALPES..CUSTOMER ALID02 ON (ALID02.CUST_CODE=ALID01.CUSTP_CODE)" strJoin = "INNER JOIN PROALPES..INVPAY ALID03 ON (ALID03.INV_FILE=ALID01.INV_FILE AND ALID03.INV_NUM=ALID01.INV_NUM)" strJoin = "INNER JOIN PROALPES..CUSTTYPE ALID07 ON (ALID07.CUSTY_CODE=ALID02.CUSTY_CODE)" strJoin = "INNER JOIN PROALPES..PAYMENT ALID08 ON (ALID08.PAY_CODE=ALID01.PAY_CODE)" strJoin = "INNER JOIN PROALPES..SALESMEN ALID09 ON (ALID09.SP_CODE=ALID01.SP_CODE)" strJoin = "LEFT OUTER JOIN PROALPES..CUSTOMDB ALID12 ON (ALID12.CUST_CODE=ALID01.CUSTP_CODE AND ALID12.BRANC_CODE=ALID01.BRANC_CODE)" strJoin = "LEFT OUTER JOIN PROALPES..CUSTTYPE ALID17 ON (ALID17.CUSTY_CODE=ALID12.CUSTY_CODE)" strJoin = "LEFT OUTER JOIN PROALPES..CONTRACT ALID18 ON (ALID18.ESRC_FILE=ALID01.ESRC_FILE AND ALID18.RC_NUM=ALID01.RC_NUM)" strWhere = "WHERE ALID01.DOC_STATUS<>5 AND ALID01.FLAG_CONSO=2 AND ( ALID01.FLAG_PAY=1) AND ALID01.TTC_AMOUNT<>0 AND ( ((ALID12.CUSTY_CODE IS NULL OR ALID12.CUSTY_CODE='') AND (ALID07.FACTOR_TYP<>1 OR ALID07.FACTOR_TYP IS NULL)) OR (ALID12.CUSTY_CODE IS NOT NULL AND ALID12.CUSTY_CODE<>'' AND (ALID17.FACTOR_TYP<>1 OR ALID17.FACTOR_TYP IS NULL)))"
Windows("xxxx.xlsm").Activate Dim strSQL As String Sheets("BDD1").Select strSQL = "SELECT ALID01.INV_FILE, ALID01.INV_NUM, ALID01.CUST_REF, ALID01.ORDERSOU, ALID01.CREAC_DATE, ALID01.MARK_CODE, ALID" strSQL = strSQL & "01.CUSTP_CODE, ALID02.ACC_CODE, ALID01.SP_CODE, ALID01.TTC_AMOUNT, ALID03.PAY_AMOUNT, ALID01.AMOUNT_SIGN, ALID01.DA" strSQL = strSQL & "TE_DUE,(ALID02.AUT_OVERD+ALID02.AUT_SFAC), ALID02.CUST_PHONE, ALID02.CUST_FAX, ALID02.SIREN_CODE, ALID01.REL1_DATE," strSQL = strSQL & " ALID01.REL2_DATE, ALID01.REL3_DATE, ALID01.BRANC_CODE, ALID01.CUST_CODE, ALID01.ESRC_FILE, ALID01.RC_NUM, ALID08.N" strSQL = strSQL & "BPAY_DAY, ALID18.SIT_NAME, ALID09.SP_CODE, ALID09.SP_NAME, ALID01.OFF_FILE, ALID01.OFF_NUM, ALID02.ACCOL_CODE, ALID" strSQL = strSQL & "02.INV_NAME,(SELECT COUNT(ALID19.PAY_NUM)" & VbCrLf & "FROM PROALPES..PAYDETUNPAID ALID19" & VbCrLf & "WHERE ALID19.INV_FILE=ALID01.INV_FIL" strSQL = strSQL & "E AND ALID19.INV_NUM=ALID01.INV_NUM)" & VbCrLf & "FROM PROALPES..INREFER ALID01" & VbCrLf & "INNER JOIN PROALPES..CUSTOMER ALID02 ON (ALID" strSQL = strSQL & "02.CUST_CODE=ALID01.CUSTP_CODE)" & VbCrLf & "INNER JOIN PROALPES..INVPAY ALID03 ON (ALID03.INV_FILE=ALID01.INV_FILE AND ALID03." strSQL = strSQL & "INV_NUM=ALID01.INV_NUM)" & VbCrLf & "INNER JOIN PROALPES..CUSTTYPE ALID07 ON (ALID07.CUSTY_CODE=ALID02.CUSTY_CODE)" & VbCrLf & "INNER JOIN " strSQL = strSQL & "PROALPES..PAYMENT ALID08 ON (ALID08.PAY_CODE=ALID01.PAY_CODE)" & VbCrLf & "INNER JOIN PROALPES..SALESMEN ALID09 ON (ALID09.SP_C" strSQL = strSQL & "ODE=ALID01.SP_CODE)" strSQL = strSQL & "LEFT OUTER JOIN PROALPES..CUSTOMDB ALID12 ON (ALID12.CUST_CODE=ALID01.CUSTP_CODE AND ALID12.BRANC_CODE=ALID01.BRAN" strSQL = strSQL & "C_CODE)" & VbCrLf & "LEFT OUTER JOIN PROALPES..CUSTTYPE ALID17 ON (ALID17.CUSTY_CODE=ALID12.CUSTY_CODE)" & VbCrLf & "LEFT OUTER JOIN PROALP" strSQL = strSQL & "ES..CONTRACT ALID18 ON (ALID18.ESRC_FILE=ALID01.ESRC_FILE AND ALID18.RC_NUM=ALID01.RC_NUM)" & VbCrLf & "WHERE ALID01.DOC_STATUS" strSQL = strSQL & "<>5 AND ALID01.FLAG_CONSO=2 AND ( ALID01.FLAG_PAY=1) AND ALID01.TTC_AMOUNT<>0 AND ( ((ALID12.CUSTY_CODE IS NULL OR" strSQL = strSQL & " ALID12.CUSTY_CODE='') AND (ALID07.FACTOR_TYP<>1 OR ALID07.FACTOR_TYP IS NULL)) OR (ALID12.CUSTY_CODE IS NOT NULL " strSQL = strSQL & "AND ALID12.CUSTY_CODE<>'' AND (ALID17.FACTOR_TYP<>1 OR ALID17.FACTOR_TYP IS NULL)))" With ActiveSheet.ListObjects.Add(SourceType:=0, Source:=Array( _ "OLEDB;Provider=MSDASQL.1;Persist Security Info=True;Extended Properties=""DSN=xxxxx;Description=xxxxx;UID=Administrateur;APP=Micr" _ , "osoft Office 2003;WSID=xxxxx;DATABASE=xxxxx"""), Destination:= _ Range("$C$1")).QueryTable .CommandType = xlCmdSql .CommandText = Array(strSQL) .RowNumbers = False .FillAdjacentFormulas = False .PreserveFormatting = True .RefreshOnFileOpen = False .BackgroundQuery = True .RefreshStyle = xlInsertDeleteCells .SavePassword = False .SaveData = True .AdjustColumnWidth = True .RefreshPeriod = 0 .PreserveColumnInfo = True .ListObject.DisplayName = _ "Tableau_SQL_Queries___xxxxx__x.x.x.x____9.16.2" .Refresh BackgroundQuery:=False End With End Sub