Beckhoff and SQL

Taco

Lifetime Supporting Member
Join Date
Aug 2004
Location
Maastricht
Posts
27
Hi there,

I have to connect to a MSSQL database. Usually I make my query using the 'FB_Formatstring' function. This works fine for normal variables. But now I have to write a DateTimeStamp to the database. I can't get it into my query using the normal 'FB_Formatstring' function. How do I get this to work? o_O

Here's an example of my code, like I use it:

FUNCTION_BLOCK UpdateSQL

VAR_INPUT
_NetID : STRING;
_DBID : UDINT;
_SEQU : DINT;
_DTS : DT;
END_VAR

VAR_OUTPUT
..............
END_VAR

VAR
fWriteSQL : FB_DBRecordInsert;
sqlComstr : FB_Formatstring;
sqlCommand : T_MaxString;
END_VAR


sqlComstr (
sFormat:='UPDATE TABLENAME SET SEQUENTIAL=%D, DATETIME=%?? WHERE IEN=111',
arg1:= F_DINT(_SEQU),
arg2:= F_?????????? ==> here should the conversion go from datetime
);





Anyone, any idea?


Thanks,

Taco
 
Here's how I do it...

Good luck,

Yosi
------------------------------------------------------------------------

FUNCTION MyGetTimeForSQL : STRING
VAR_INPUT
END_VAR
VAR
DTString:STRING;
MyJunkStr:STRING;
END_VAR

DTString := DT_TO_STRING(SysRtcGetTime(TRUE)); (* Get the data *)
DTString := RIGHT(DTString,LEN(DTString)-LEN('DT#')); (* Strip off the DT# from the front of the string *)
MyJunkStr := CONCAT(LEFT(DTString,LEN('xxxx-xx-xx')),' '); (* Strip out the '-' from between the date and the time *)
DTString := CONCAT(MyJunkStr, RIGHT(DTString,LEN('xx:xx:xx')));

MyJunkStr := CONCAT('$'',DTString); (* Add $' before and after the updated timestamp *)
MyGetTimeForSQL := CONCAT(MyJunkStr, '$'');
 

Similar Topics

Hi everyone, This is my first time posting, so please forgive any omissions or mistakes. I am attempting to control the velocity of a stepper...
Replies
18
Views
1,002
Hello sameone have Beckhoff PLC Siemens Sinamics V90 configuration example?
Replies
0
Views
98
hello, I am using Beckhoff with TwinCAT3 and when I change or add some new hardware or for any reason, there is a mismatch in the real hardware vs...
Replies
1
Views
126
I have a Beckhoff CX7000 IPC with some digital I/O built-in and I additionally need two analog inputs 0-10V. Can I install both Ethernet terminals...
Replies
4
Views
207
Hello, We are currently working on a project that involves connecting a linear potentiometer to our Beckhoff PLC. After researching, we...
Replies
2
Views
197
Back
Top Bottom