Page 1 of 1 1
Topic Options
#90466 - 2002-12-10 02:16 AM Table Join Inventory stuff
Jose Offline
Seasoned Scripter
*****

Registered: 2001-04-04
Posts: 693
Loc: Buenos Aires - Argentina
Hi Boys!! Late isnt it?........bothering with table stuff again. Here i go! [Big Grin]

I have three tables Users, Machine and Relations (in fact they are more like software, an another to come) and i cannot join them. I have read the access helt and found and example but cannot make it work. I do make them work individually (Users and Machine) but not Relations with ID_Users and ID_Machine.
Here is the code:
code:
CLS
SetOption("WrapAtEOL","On")
$Connectionstring = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=\\server\kixexe$$\database\logon.mdb"
$Connection = CreateObject ("ADODB.Connection")
$Command = CreateObject ("ADODB.Command")
$recordset = CreateObject ("ADODB.RecordSet")
$Connection.connectionstring = $Connectionstring
$Connection.Open
$Command.activeconnection = $Connection
$recordset.curecordsetortype = 3
$recordset.locktype = 3
$recordset.Activecommand = $Command
$CommandtxtUsuario = "select * from usuario" ;INNER JOIN Relaciones ON Usuario.Id_Usuario = Relaciones.Id_Usuario"
$Command.commandtext = $CommandtxtUsuario $recordset.Open ($Command)

$recordset.addnew
$recordset.fields.item("Usuario").value = @USERID
$recordset.fields.item("Nombre_Completo").value = @FullName
$recordset.fields.item("Grupo").value = @PrimaryGroup
$recordset.fields.item("Computadora").value = @WKSTA
$recordset.fields.item("Dia").value = $DIAENTERO
$recordset.fields.item("Hora").value = @TIME
$recordset.update
$recordset.Close

$CommandtxtMaquina = "select * from Maquina" ;INNER JOIN Relaciones ON Usuario.Id_Maquina = Relaciones.Id_Maquina"
$Command.commandtext = $CommandtxtMaquina $recordset.Open ($Command)
$recordset.addnew
$recordset.fields.item("Ip").value = @ipaddress0
$recordset.fields.item("Server").value = @LSERVER
$recordset.fields.item("Cpu").value = @CPU
$recordset.fields.item("So").value = @ProductType
$recordset.fields.item("Idioma").value = @SYSLANG
$recordset.fields.item("MAC").value = @Address
$recordset.fields.item("Service_Pack").value = $Service_Pack
$recordset.fields.item("Install_Date").value = $Install_Date
$recordset.fields.item("Disco").value = $Disco
$recordset.fields.item("Res_Video").value = $Res_Video
$recordset.update
$recordset.Close

I have seen a similar example - here -where sealeopard suggested to use something lie this but cannot work it out
code:
SELECT ComputerID FROM tblComputer WHERE ComputerName=@WKSTAINSERT INTO tblSoftware (SoftwareName) Values (SoftwareName)

Thanks again for your help its a big hand.
_________________________
Life is fine.

Top
#90467 - 2002-12-10 02:45 AM Re: Table Join Inventory stuff
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
The simplest solution is a three step process
1) retrieve userid (SELECT UserID FROM tblUser WHERE UserName="@USERID")
2) retreive computerid (SELECT ComputerID FROM tblComputer WHERE computerName="@WKSTA")
3) insert into lookup table (INSERT INTO tblLoginLog VALUES(UserID,ComputerID,LoginTime) SET (UserId,ComputerId,@TIME)

Be advised that this is only the framework.

Also, you might want to use the DB... UDFs that are posted in the UDF Forum, this will make coding database connectivity much easier.

The SQL statements can be compacted into a single lien, though. However, the outline above is easier to understand.
_________________________
There are two types of vessels, submarines and targets.

Top
#90468 - 2002-12-10 04:25 AM Re: Table Join Inventory stuff
Jose Offline
Seasoned Scripter
*****

Registered: 2001-04-04
Posts: 693
Loc: Buenos Aires - Argentina
The Fu....... [Mad] cable service went down!! [Mad] Ahhhhhh!!....but...... [Big Grin]
Thanks for the quik answer sealeopard but i still have a doubght. Let me please put it this way.
Suppose this is a every-day log file database I want to keep records for statistics.
If the SELECT retrieve userid how can i be sure that is the last one, cause I thought to have three differents Id (Autonumeric) values of three different tables to be written in a relation table. Something like this if let me show it to you.
 -
Sorry for the language but this can show what i am willing to do.
I reckon the method would be to write the thee tables take their Ids and write the Relations table. What do you think. Am I very wrong?

[ 10. December 2002, 04:26: Message edited by: jose3 ]
_________________________
Life is fine.

Top
#90469 - 2002-12-10 04:41 AM Re: Table Join Inventory stuff
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
how about this as a reference...

 -

http://www.wheelerfam.com/Documents/inventory.kix
http://www.wheelerfam.com/Documents/Inventory.mdb

Much of it has to do with normilization, and determining what actually needs to be updated.
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#90470 - 2002-12-10 05:12 AM Re: Table Join Inventory stuff
Jose Offline
Seasoned Scripter
*****

Registered: 2001-04-04
Posts: 693
Loc: Buenos Aires - Argentina
IOU!! Radimus.......you are a gentleman....MAN!! [Big Grin]
Thank you very much for your files as i can see u used $SerNo (SerialNumber) to relate inventory, computers and software as an example.
Fery usefull. I have something to play with [Razz] .
Tenks

[ 10. December 2002, 05:14: Message edited by: jose3 ]
_________________________
Life is fine.

Top
Page 1 of 1 1


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

Who's Online
0 registered and 857 anonymous users online.
Newest Members
JimDunn, fgarcia, Viginette, ManuvdWielNL, Sir_Barrington
17890 Registered Users

Generated in 0.052 seconds in which 0.022 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