Jump to content

Recommended Posts

Posted (edited)
select top 0 * into #tmpdatabase from ABTABLE;

select * from #tmpdatabase;

BULK INSERT #tmpdatabase FROM $fileupload WITH (FIELDTERMINATOR =';',ROWTERMINATOR ='\n' ,FIRSTROW = 2);

MERGE ABTABLE AS T
  USING #tmpdatabase AS S
    ON (T.A = S.A)
     WHEN NOT MATCHED BY TARGET
         THEN INSERT(
                      [A]
                     ,[K]
                     )
             VALUES(
                      S.[A]
                     ,S.[K]
                   )
     WHEN MATCHED
         THEN UPDATE
             SET      T.[A] = S.[A]
                     ,T.[K] = S.[K];

drop table #tmpdatabase;

Hi, I'm trying to convert this query that I make from Toad that loads a file into a tempdatabase from .csv file based on an existing table on the sql server into autoit friendly code but don't know how to do it, been rubbing my head on this one :P, maybe need a different approach?

I'm using AutoIt Version: 3.3.10.2

 

This doesn't seem to do anything:

Local $obj_SQL_DB = _SQLConnect("db.u\SQl1", "data", 1, "At", "Pass")
    If @error Then Return SetError(50, @error, -1)
    
    Local $strSQL = "select top 0 * into #tmpdatabase from ABTABLE;"
    $obj_SQL_DB.Execute($strSQL)

Any suggestions would be fantastic :)

Nevermind i managed to do this like this instead :), mark as solved!

Local $file = FileOpen("\TEST\SQL_UPD.txt",0)
    Local $strSQL = FileRead($file)
    $obj_SQL_DB.Execute($strSQL)

 

Edited by smellyfingers
Posted

Maybe here:

 

 

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

 

An alternative: I think you are looking at two steps. Read the CSV, and then the SQL connection, and insert.  See @czardas's CSVSplit UDF (it also reads CSVs) to begin with.

Skysnake

Why is the snake in the sky?

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...