From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

database SELECT SYNTAX

Solved!
Go to solution

Before doing your select statement, have you selected the database to use ?

 

Try to make a small vi that demonstrate what you are doing and post it here.

0 Kudos
Message 11 of 20
(2,490 Views)

 

 

Edit: I didn't see your other post so the semicolon is probably not the problem. What does the server error log say?

=====================
LabVIEW 2012


0 Kudos
Message 12 of 20
(2,486 Views)

select top 1 id from SensoresIR1 order by id desc

 

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 13 of 20
(2,463 Views)

Just going back to your original post where your SQL statement didn't work the reason is as follows...

 

SELECT id FROM SensoresIR1 WHERE id=36151  = ERROR!

 

SELECT id FROM SensoresIR1 WHERE id='36151'  = GOOD Smiley Very Happy

 

ie. you just need to put apostrophes around the value that you want to search for - this syntax will work of MySQL and MS SQL databases.

 

 

Chris

0 Kudos
Message 14 of 20
(2,451 Views)

 


@Chris Reed wrote:

 

ie. you just need to put apostrophes around the value that you want to search for - this syntax will work of MySQL and MS SQL databases.

 

 

Chris


nomade42k, I would be interested to hear from you if that worked. You do not have to quote numeric datatypes although you can. I can not speak to MySQL or MS SQL as I only use PostgreSQL. I know that MySQL has some funky syntax. Is id a string? That would totally explain the error Smiley Very Happy

 

 

The reason I did not think it was a string is because you said it is automatically assigned by the server which implies it is an integer sequence.

=====================
LabVIEW 2012


0 Kudos
Message 15 of 20
(2,447 Views)

Hello!

 

here I leave you my block VI and the DB with its columns (in spanish)

 

It still doesn´t work...

 

 

Download All
0 Kudos
Message 16 of 20
(2,433 Views)

I think you need to quote your time string. I don't know if MySQL uses single or double quotes.

 

quote time.png

 

 

=====================
LabVIEW 2012


0 Kudos
Message 17 of 20
(2,415 Views)
Solution
Accepted by nomade42k

After looking at this some more I notice you are using the select vi. You are sending the entire SQL statement to the where clause input. There is a vi under advanced called 'execute query' which you will want to use when you are building the statement yourself. The select just requires the table input and an array of columns.

 

Try something like this. You may need to change the quote from single to double (or remove the quote if the DB tools is smart enough to quote the parameters. I have never used it)

 

select.png

=====================
LabVIEW 2012


Message 18 of 20
(2,410 Views)

select data.png

Err message disapears after add 'where' in my case 😉

0 Kudos
Message 19 of 20
(2,009 Views)

@Onin wrote:

select data.png

Err message disapears after add 'where' in my case 😉


If memory serves, the Select function adds Where automatically (if the string is not empty), so you'll get a double Where in this case.

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 20 of 20
(1,993 Views)