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: 

Decimal Place issue - unable to insert into Database

Solved!
Go to solution

I have a really simple problem and I've tried a couple of solutions found elsewhere but just can't seem to get this right.

 

I have two values, which are initially imported via a Database query (SQL), then the value written into a DBL Control.  Once altered, I then want to put it back using Database Insert and create a new record.  My problem lies with once I've changed the value, and pressed the button, the value sent to the Database isn't the formatted value I need (and I have tried converting to a string, setting the width, setting the display format of the control - nothing seems to work).

 

Screenshot attached shows the resultant data, it errors as my SQL column is set to Decimal(6,2).

 

All I want is a value like 1234.56

 

Am I just being really stupid here?!

0 Kudos
Message 1 of 15
(3,888 Views)

What is the error message?

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 2 of 15
(3,850 Views)
Possible reason(s):
ADO Error: 0x80040E57
Exception occured in Microsoft OLE DB Provider for ODBC Drivers: [Microsoft][ODBC SQL Server Driver][SQL Server]Arithmetic overflow error converting float to data type numeric. in NI_Database_API.lvlib:Rec Create - Command.vi->NI_Database_API.lvlib:Cmd Execute.vi->NI_Database_API.lvlib:DB Tools Insert Data.vi->Update CdV Factor.vi
0 Kudos
Message 3 of 15
(3,839 Views)

Are your column names [1] and [10]?  I doubt that special characters are allowed.  Give your columns an actual name with alpha characters. 

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 4 of 15
(3,825 Views)

Yes they are called 1 & 10, I've used the square brackets to ensure they a relative name, not an actual value, but I will test that theory, but I usually write data back to this table by other methods and have no issues.

0 Kudos
Message 5 of 15
(3,822 Views)

@aputman wrote:

Are your column names [1] and [10]?  I doubt that special characters are allowed.  Give your columns an actual name with alpha characters. 


Having amended the table and changed the column names to the words "One" and "Ten", I can confirm this still doesn't resolve the issue.  It was worth a try but was 99.9% sure this wasn't the issue, but having learned from LabVIEW experience, sometimes expect the unexpected!

0 Kudos
Message 6 of 15
(3,767 Views)

This is one of "Those Times" you need to use "Bundle By Name" rather than "Bundle"


"Should be" isn't "Is" -Jay
Message 7 of 15
(3,751 Views)

With a datatype of decimal(6,2), the maximum number of digits you can have is 4 on the left side and 2 on the right side of the decimal point. The 2 forces every value to have 2 decimal places, even though they may be zeros.  You won't be able to insert 12345 because it assumes there are two decimal places.  Your number becomes 12345.00 and you've now exceeded the 6 digit limit.  Check your data to make sure you don't have any numbers with 5 or more digits on the left side of the decimal. 

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 8 of 15
(3,739 Views)

@aputman wrote:

With a datatype of decimal(6,2), the maximum number of digits you can have is 4 on the left side and 2 on the right side of the decimal point. The 2 forces every value to have 2 decimal places, even though they may be zeros.  You won't be able to insert 12345 because it assumes there are two decimal places.  Your number becomes 12345.00 and you've now exceeded the 6 digit limit.  Check your data to make sure you don't have any numbers with 5 or more digits on the left side of the decimal. 


That is correct and what I'm expecting to see; my usual, largest value would be around 5755.25 - so no wider than 6 digits, I have a feeling when I'm going through the Data to Variant function, that's having the undesired effect I'm seeing, but that's what the Database Insert VI wants from the source data.

0 Kudos
Message 9 of 15
(3,725 Views)

I should point out that the column labels in the image are reversed from the actual order of the data fields.

 

The DB toolkit is a set of unlocked VIs.  Drill down to DB Tools Insert Data.vi -> DB Tools Create Parameterized Query.vi and examine the parameters out array.  This will identify how the data has been interpreted.  You can expand all the SubVIs here until you can see the actual value being written.

Michael Munroe, CLD, CTD, MCP
Automate 1M+ VI Search, Sort and Edit operations with Property Inspector 5.0, now with a new Interactive Window Manager!
Now supports full project automation using one-click custom macros or CLI.
0 Kudos
Message 10 of 15
(3,713 Views)