Sqlserver
 sql >> Datenbank >  >> RDS >> Sqlserver

Validieren Sie Daten vor dem Hochladen über SSIS

Es ist möglicherweise am einfachsten, in eine temporäre Tabelle zu laden, die keine obligatorischen Werte usw. enthält, und dies zu überprüfen, bevor Sie sie an die Haupttabelle anhängen.

BEARBEITEN zum Kommentar

Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset 

''This is not necessarily the best way to get the workbook name
''that you need
strFile = Workbooks(1).FullName

''Note that if HDR=No, F1,F2 etc are used for column names,
''if HDR=Yes, the names in the first row of the range
''can be used. 
''This is the Jet 4 connection string, you can get more
''here : http://www.connectionstrings.com/excel

 strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strFile _
    & ";Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1"";"

Set cn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")

cn.Open strCon

''Note that HDR=Yes
''Pick one:
strSQL = "SELECT Frst, Secnd FROM TheRange WHERE SomeField Is Null" ''Named range
strSQL = "SELECT Frst, Secnd FROM [Sheet1$C3:C67] WHERE Val(Secnd)=0" ''Range
strSQL = "SELECT Frst, Secnd FROM [Sheet1$] WHERE First<Date()" ''Sheet

rs.Open strSQL, cn

Sheets("Sheet2").Cells(2, 1).CopyFromRecordset rs