Jump to content
Sign in to follow this  
bandersen

Transfer values to a query

Recommended Posts

bandersen

Hi

I try to send the following values through a query:

Func _SQLQueryComputerData($pc_serial,$sIP,$pc_model_short)

$query="INSERT INTO Data (Model, Service_Tag, IP) VALUES($pc_serial,$sIP,$pc_model_short)"

$conn.EXECUTE($query)

Return 1

EndFunc

But I get an error. The query works fine when the values are typed in like this:

$query="INSERT INTO Data (Model, Service_Tag, IP) VALUES('D620','HJHJK8J','10.116.115.16')"

How do I get the query to use the values inside variables?

BR

Benjamin

Share this post


Link to post
Share on other sites
water

Try:

Func _SQLQueryComputerData($pc_serial,$sIP,$pc_model_short)
    
    $query="INSERT INTO Data (Model, Service_Tag, IP) VALUES(" & $pc_serial & "," & $sIP & "," & $pc_model_short & ")"
    $conn.EXECUTE($query)   
    Return 1    
EndFunc

or if SQL requires quotes:

Func _SQLQueryComputerData($pc_serial,$sIP,$pc_model_short)
    
   $query="INSERT INTO Data (Model, Service_Tag, IP) VALUES('" &$pc_serial & "','" & $sIP & "','" & $pc_model_short &"')"
    $conn.EXECUTE($query)   
    Return 1    
EndFunc
Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
bandersen

Hi

Thanks, I finally got it working >_< Thanks for the help.

I am writing to a SQL database and I use the following commands:

$query="INSERT INTO Data (IP) VALUES('"& $pc_model_short &"')"

BR

Benjamin

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.