2009-07-09 3 views
0

Oracle 데이터베이스 및 워크 시트의 쿼리를 자동화하는 VBA를 통해 조정 도구를 구축 중입니다. 쿼리를 실행할 때 사용자가 ITEM (이 경우 파이프 라인)에서 쿼리 (워크 시트에 항목이 많음) 및 종료/시작 날짜를 입력하게합니다.
2) 어떻게 위로 지울 수 있습니다 "데이터를 사용할 수 없습니다"반환 값이 NULL 인 경우, 어떻게 인쇄하도록 지시 할 수있다 -VBA에서 문자열로 날짜 변환 및 자동화 프로그램에 대한 이전 SQL 데이터 출력 지우기

1)이 쿼리입니다 : 나는 문제가 다음 파악을 데 이전 SQL 문/파이프 라인 A에서 데이터 출력, 파이프 라인 B를 쿼리 할 때?
3) 날짜가 오라클에 문자열로 저장됩니다 - 어떻게 날짜로 변환 할 수 있습니까?
감사합니다. 내가이 상황을 타개하고자한다면 또한

Option Explicit Option Base 1 Dim cnnObject As ADODB.Connection Dim rsObject As ADODB.Recordset Dim strGPOTSConnectionString As String Dim Pipeline As String Dim DateStart As Date Dim DateEnd As Date Dim strQuery As String Sub ClickButton2() Debug.Print ("Button has been clicked") Pipeline = InputBox("Enter PipeLine", "My Application", "Default Value") DateStart = InputBox("Enter Start Date", "My Application", DateTime.Date) DateEnd = InputBox("Enter End Date", "My Application", DateTime.Date + 1) Range("B1").Value = Pipeline Range("B2").Value = DateStart Range("B3").Value = DateEnd strQuery = "select pipelineflow.lciid lciid, ldate, volume, capacity, status, " & _ "pipeline, station, stationname, drn, state, county, owneroperator, companycode, " & _ "pointcode, pointtypeind, flowdirection, pointname, facilitytype, pointlocator, " & _ "pidgridcode from pipelineflow, pipelineproperties " & _ "where pipelineflow.lciid = pipelineproperties.lciid " & _ "and pipelineflow.audit_active = 1 " & _ "and pipelineproperties.audit_active =1 " & _ "and pipelineflow.ldate >= '" & Format(DateStart, "dd-MMM-yyyy") & "' and pipelineflow.ldate < '" & Format(DateEnd, "dd-MMM-yyyy") & "' " & _ "and pipelineproperties.pipeline = '" & Pipeline & "' " Call PullZaiNetData(strQuery) Call TieOut End Sub Sub PullZaiNetData2(ByVal strQry As String) Set cnnObject = New ADODB.Connection Set rsObject = New ADODB.Recordset strGPOTSConnectionString = "DRIVER={Microsoft ODBC for Oracle}; SERVER=XYZ; PWD=XYZ; UID=XYZ" cnnObject.Open strGPOTSConnectionString rsObject.Open strQry, cnnObject, adOpenStatic Worksheets("ZaiNet Data").Cells(1, 1).CopyFromRecordset rsObject rsObject.Close cnnObject.Close Set rsObject = Nothing Set cnnObject = Nothing End Sub Sub TieOut() End Sub 

가, 내가 할 수있는 방법을 대신 셀에 사용자가 입력 한 날짜와 파이프 라인이

를 입력하지 : 여기

는 지금까지이 무엇인가? 설정과 같은 작업을해야한다는 것을 알고 있습니다.

startDate = Worksheets("Instructions").Cells(5, 4).Value 

하지만 이것이 가능합니까?

답변

1
  1. null을 바꾸려면 Oracle의 NVL 기능을 사용할 수 있습니다. 예 : "('데이터를 사용할 수 없습니다'를 pipelineflow.lciid) NVL 선택 ..."

  2. 당신이 워크 시트 ("ZaiNet 데이터")를 사용할 수 있습니다 오래된 데이터를 지우려면. Cells.Clear

  3. 변환하려면 날짜의 날짜 문자열은 오라클의 TO_DATE 함수를 사용합니다. "SELECT TO_DATE (ldate, 'dd-mon-yyyy') ...", 여기서 dd-mon-yyyy는 데이터베이스에있는 날짜 문자열의 날짜 형식입니다.

워크 시트에서 날짜를 읽는 코드는 셀의 값을 날짜로 전송할 수있는 한 작동합니다. 워크 시트 유효성 검사를 사용하여 사용자가 유효한 날짜 만 입력 할 수 있도록 할 수 있습니다.

관련 문제