You are not registered yet. Please click here to register!


 
 
plc storereviewsdownloads
This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc.
 
Try our online PLC Simulator- FREE.  Click here now to try it.

New Here? Please read this important info!!!


Go Back   PLCS.net - Interactive Q & A > PLCS.net - Interactive Q & A > LIVE PLC Questions And Answers

Reply
 
Thread Tools Display Modes
Old February 1st, 2023, 08:52 AM   #1
del1
Member
Slovenia

del1 is offline
 
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
  Reply With Quote
Old February 1st, 2023, 09:32 AM   #2
Corsair
Lifetime Supporting Member
United States

Corsair is offline
 
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.
  Reply With Quote
Old February 1st, 2023, 10:06 AM   #3
drbitboy
Lifetime Supporting Member
United States

drbitboy is offline
 
drbitboy's Avatar
 
Join Date: Dec 2019
Location: Rochester, NY
Posts: 6,710
Quote:
Originally Posted by Corsair View Post
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.

+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.
  Reply With Quote
Old February 2nd, 2023, 01:48 AM   #4
del1
Member
Slovenia

del1 is offline
 
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.
Attached Images
File Type: jpg Table scheme.jpg (98.7 KB, 60 views)
  Reply With Quote
Old February 2nd, 2023, 02:12 AM   #5
del1
Member
Slovenia

del1 is offline
 
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.
  Reply With Quote
Old February 2nd, 2023, 05:59 AM   #6
parky
Member
United Kingdom

parky is offline
 
parky's Avatar
 
Join Date: Oct 2004
Location: Midlands
Posts: 4,934
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.
  Reply With Quote
Old February 2nd, 2023, 06:37 AM   #7
del1
Member
Slovenia

del1 is offline
 
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..
  Reply With Quote
Old February 5th, 2023, 03:36 AM   #8
sigmadelta
Member
Canada

sigmadelta is offline
 
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.
  Reply With Quote
Old February 13th, 2023, 03:05 AM   #9
del1
Member
Slovenia

del1 is offline
 
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
  Reply With Quote
Old February 13th, 2023, 08:04 AM   #10
drbitboy
Lifetime Supporting Member
United States

drbitboy is offline
 
drbitboy's Avatar
 
Join Date: Dec 2019
Location: Rochester, NY
Posts: 6,710
Quote:
Originally Posted by del1 View Post
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

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.
  Reply With Quote
Reply
Jump to Live PLC Question and Answer Forum


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Topics
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


All times are GMT -4. The time now is 05:43 AM.


.