Page 1 of 1 1
Topic Options
#113828 - 2004-02-11 07:38 PM Problem updating fields
Chaguito Offline
Getting the hang of it

Registered: 2002-05-17
Posts: 53
Hello all....I have a script that writes to an access db and everytime it runs it duplicates the data. Any way to instead of duplicating or deleting the field, update it...

Here is the script...inputs are welcome!!!!

Code:
  
; Call Database.udf which contains
; DBConnOpen()
; DBConnClose()
; DBCommand()
; DBExecuteSQL()
; DBGetRecordset()
; DBRecordsetOpen()
; DBRecordsetClose()

If Exist("database.udf") = 1 call database.udf Else ? "database.udf not found. Aborting..." Sleep 3 goto end Endif

$objConn = DBConnOpen('DRIVER={Microsoft Access Driver (*.mdb)}; UID=; PWD=; DBQ=c:\test.mdb')

:ComputerInfo

$SQL1="INSERT INTO COMPUTERS VALUES ('@WKSTA','@USERID','@PRIV','@DOMAIN','@PRODUCTTYPE','@CSD','@IPADDRESS0','@ADDRESS');"
$execute=DBCommand($objConn,$SQL1)

:UserInfo

$SQL2="INSERT INTO Users VALUES ('@USERID','@FULLNAME','@MAXPWAGE','@WKSTA','@LSERVER');"
$execute=DBCommand($objConn,$SQL2)

:HardwareInfo

$memory=MEMORYSIZE()

$SQL3="INSERT INTO Hardware VALUES ('@WKSTA','$memory','@CPU','@MHz');"
$execute=DBCommand($objConn,$SQL3)


:END
? Exit



_________________________
Chaguito, MCP

Top
#113829 - 2004-02-11 07:39 PM Re: Problem updating fields
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
You'd need to change your SQL code to use UPDATE TABLE instead of INSERT INTO and modify the logic to differentiate between these two.
_________________________
There are two types of vessels, submarines and targets.

Top
#113830 - 2004-02-11 07:48 PM Re: Problem updating fields
Chaguito Offline
Getting the hang of it

Registered: 2002-05-17
Posts: 53
Quote:

You'd need to change your SQL code to use UPDATE TABLE instead of INSERT INTO and modify the logic to differentiate between these two.




How it is right now is like it was ran for the first time, I am just stuck on the update part. I know the command to update the field but which would be the SQL statements that will filter between first time or update field.
_________________________
Chaguito, MCP

Top
#113831 - 2004-02-11 08:26 PM Re: Problem updating fields
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
You will first have to check whether there's already an entry present based on some kind of unique identifier. Then you perform the appropriate UPDATE or INSERT INTO.

Edited by sealeopard (2004-02-11 08:27 PM)
_________________________
There are two types of vessels, submarines and targets.

Top
#113832 - 2004-02-11 08:54 PM Re: Problem updating fields
Chaguito Offline
Getting the hang of it

Registered: 2002-05-17
Posts: 53
The identifier will be the @WKSTA but I cant seem to find a way to query if it exists or not so that the script will INSERT or UPDATE.

For example...
If the @WKSTA exist already on the table then UPDATE
If the @WKSTA not on table then INSERT

I am pretty much a newbie with SQL statements.

All the help is very appreciated!!!!!
_________________________
Chaguito, MCP

Top
#113833 - 2004-02-11 09:22 PM Re: Problem updating fields
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
If the workstation name is already present in the table, then a SELECT query would retrieve this record. You might want to read a SQL book or tutorial.
_________________________
There are two types of vessels, submarines and targets.

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 781 anonymous users online.
Newest Members
Sir_Barrington, batdk82, StuTheCoder, M_Moore, BeeEm
17886 Registered Users

Generated in 0.054 seconds in which 0.026 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org