![]() ![]() ![]() ![]() ![]() ![]() |
||
![]() |
||
![]() ![]() ![]() ![]() This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc. |
||
![]() |
|
![]() |
#1 |
Member
![]() ![]() Join Date: Feb 2023
Location: CE
Posts: 5
|
WinCC -> SQL real datatype
Hello all!
I have a problem with data logging from winCC to SQL server. I am trying to write a single variable type "Real" to SQL server. The problem is that SQL table doesn't show the decimal places. Data type of the variable in SQL database is also Real. "data1" is a HMI tag connected to a DB value of type Real in PLC. If I send value 5.0, only 5 is written into the database. VB script code: Sub VBFunction_2() Dim objConnection Dim strConnectionString Dim strSQL Dim objCommand Dim Data1 strConnectionString = "Provider=MSDASQL;DSN=TestODBC;UID=;PWD=;" Data1=SmartTags("data1") strSQL = "INSERT INTO TableReal (Number) VALUES ( " & Data1 & " );" Set objConnection = CreateObject ("ADODB.Connection") objConnection.ConnectionString = strConnectionString objConnection.Open Set objCommand = CreateObject("ADODB.Command") With objCommand .ActiveConnection = objConnection .CommandText = strSQL End With objCommand.Execute Set objCommand = Nothing objConnection.Close Set objConnection = Nothing End Sub Has anyone experienced similar issues? Thank you for helping ![]() |
![]() |
![]() |
#2 |
Lifetime Supporting Member
![]() ![]() Join Date: Dec 2020
Location: Missouri
Posts: 188
|
My quick answer is that I think when the column is created in the database there are some parameters like 'precision' that have to be set. I don't know if you can modify them on an existing column. The requirements for the parameters vary with the type of the data.
|
![]() |
![]() |
#3 | |
Lifetime Supporting Member
|
Quote:
+1. Can you post the SQL database schema (e.g. see here)?
__________________
_ Brian T. Carcich i) Take care of the bits, and the bytes will take care of themselves. ii) There is no software problem that cannot be solved with another layer of indirection. iii) Measurement is hard. iv) I solemnly swear that I am up to no good ![]() v) I probably have the highest ratio of forum posts to actual applications in the field (∞). vi) Hakuna matata. vii) Bookkeeping. |
|
![]() |
![]() |
#4 |
Member
![]() ![]() Join Date: Feb 2023
Location: CE
Posts: 5
|
Thank you for replying,
I found no such parameter as "precision", either in an existing table or when creating a new one. Please see the table scheme in the attachment. |
![]() |
![]() |
#5 |
Member
![]() ![]() Join Date: Feb 2023
Location: CE
Posts: 5
|
SQL data type "Decimal" has parameters "precision" and "scale". If I set "scale" to 2, all existing values in the table are now represented with two decimal places, eg. 5 -> 5.00.
But I still cannot write variables of datatype Real from WinCC to SQL. If I now send value 5.0, I get 5.00 in the table, which is OK. But if I send 5.5, it is not written into the table at all. |
![]() |
![]() |
#6 |
Member
|
Try changing the SQL table to float, I seem to remember having a similar problem but not being at home I cannot confirm, I know there is a problem with some transactions from say certain scada systems & SQL. I know we had to format some real numbers from recipes that had been populated to a DB by an old style BPCS system.
|
![]() |
![]() |
#7 |
Member
![]() ![]() Join Date: Feb 2023
Location: CE
Posts: 5
|
No luck, with float column 5.0 is again displayed as 5 and 5.5 isn't written at all..
|
![]() |
![]() |
#8 |
Member
![]() ![]() Join Date: Apr 2016
Location: From Canada - Living in Bulgaria
Posts: 1,952
|
I use the real data type in SQL with WinCC with no problem. The data type of the "Data1" tag also must be real, otherwise it will be treated as an INT (or DINT).
Your main problem is that you don't have an identity column. SQL MUST have unique rows. Duplicate rows create ambiguity. Create a second column called ID (or whatever you want) and make it the primary key, set the data type to bigint, and set the "Is Identity" to "yes" in the properties. Then you can insert more than one row. As you have your program, you can only INSERT a specific value once and never again. If you want to keep your table as you have it with a single row, your first INSERT command must change to an UPDATE command in order to update that same row. Alternatively you could do "DELETE from TableReal" then execute your INSERT. strSQL = "UPDATE TableReal SET Number = " & Data1 & ";"
__________________
Automation Programmer PLC / HMI / SCADA / SQL New Systems, Modifications System Upgrades & Conversions Siemens EPROM & EEPROM Service ------------------------ Visit: contrologica.com Email: info@contrologica.com Last edited by sigmadelta; February 5th, 2023 at 03:52 AM. |
![]() |
![]() |
#9 |
Member
![]() ![]() Join Date: Feb 2023
Location: CE
Posts: 5
|
Solved: the problem was in the settings of the PC on which SQL server is running. The decimal separator sign (Controlpanel -> Regional settings) must be set to ".". Mine was set to ",", that's why SQL table didn't accept Real values.
Thank you all for helping, BR |
![]() |
![]() |
#10 | |
Lifetime Supporting Member
|
Quote:
Thanks for the feedback!
__________________
_ Brian T. Carcich i) Take care of the bits, and the bytes will take care of themselves. ii) There is no software problem that cannot be solved with another layer of indirection. iii) Measurement is hard. iv) I solemnly swear that I am up to no good ![]() v) I probably have the highest ratio of forum posts to actual applications in the field (∞). vi) Hakuna matata. vii) Bookkeeping. |
|
![]() |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Connecting WinCC Flexible to SQL Server | Prince | LIVE PLC Questions And Answers | 1 | March 10th, 2015 03:31 PM |
WinCC Flexible 2008 SQL Database Stored Procedure | ryang112 | LIVE PLC Questions And Answers | 1 | March 10th, 2015 03:10 PM |
WinCC - Report Designer - SQL problem | Lesa | LIVE PLC Questions And Answers | 0 | April 4th, 2011 04:03 AM |
Strings WinCC -> S7-400 | Jeebs | LIVE PLC Questions And Answers | 2 | June 4th, 2010 10:43 AM |
WINCC - SQL instructions | Fritz_frederix | LIVE PLC Questions And Answers | 1 | May 5th, 2003 09:02 PM |