简体   繁体   English

TM1:错误:“|”附近的语法不正确 (将数值插入 sql 查询)

[英]TM1 : Error :Incorrect syntax Near '|' (inserting numeric value into sql query)

I am trying to insert a numeric variable 'Value ' into a decimal database column.我正在尝试将数字变量“Value”插入到十进制数据库列中。

I used this query syntax:我使用了这个查询语法:

SQL= 'INSERT INTO DB_Archive VALUES ( '''| dim1|''' , '''| dim2|''', '|Value|') ';

But it seems it's not correct way to declare a numeric column, which gave me this error:但似乎声明数字列的方法不正确,这给了我这个错误:

Error : Incorrect syntax Near '|'

I tried then converting the numeric value to a string value like this:我尝试将数值转换为字符串值,如下所示:

zAmoun= NumberToString(Value);
SQL= 'INSERT INTO DB_Archive VALUES ( '''| dim1|''' , '''| dim2|''', '''|StringToNumber(zAmount)|''') ';

But it was a bad move to do, since it worked in the compilation and didnt return no error but in the execution it return this error here since the table column is a decimal:但这是一个糟糕的举动,因为它在编译中工作并且没有返回任何错误但是在执行中它在这里返回此错误,因为表列是小数:

Error : Error Converting data Type varchar to numeric

I would love if someone could help me know what is the correct syntax to declare a numeric column in sql query, since the first declaration is not working.如果有人可以帮助我了解在 sql 查询中声明数字列的正确语法是什么,我会很高兴,因为第一个声明不起作用。

I would appreciate it very much.我将不胜感激。

Maybe this Information can help you:也许这些信息可以帮助您:

At the start: Please don't start variable names with upper cases.开头:请不要以大写开头的变量名。 Make something like vSQL or sqlRequest.制作类似 vSQL 或 sqlRequest 的东西。

You try to build a SQL-Command with a string.您尝试使用字符串构建 SQL 命令。 The hole string cannot include nummeric.孔字符串不能包含数字。 TM1 is realy strict with it. TM1 对此非常严格。 Every number must be converted to String.每个数字都必须转换为字符串。

vsValue = NumberToString(value);
vsSQL= 'INSERT INTO DB_Archive VALUES ( '''| dim1|''' , '''| dim2|''', '''|vsValue|''') ';

Maybe your SQL-Target need the value in a specific form.也许您的 SQL-Target 需要特定形式的值。 For example with a "," as decimal seperator.例如,使用“,”作为十进制分隔符。 Therefore you can us the command NumberToStringEx() .因此,您可以使用命令NumberToStringEx()

vsValue = NumberToStringEx(value, '0.0####', ',', '.');
vsSQL= 'INSERT INTO DB_Archive VALUES ( '''| dim1|''' , '''| dim2|''', '''|vsValue|''') ';

here you find additional information 在这里您可以找到更多信息

With quotation marks you will give your sql-target the information, if the value is numeric or string.如果值是数字或字符串,您将使用引号为您的 sql-target 提供信息。 So maybe it's necessary to delete the quotation marks:所以也许有必要删除引号:

vsValue = NumberToString(value);
vsSQL= 'INSERT INTO DB_Archive VALUES ( '''| dim1|''' , '''| dim2|''', '|vsValue|') ';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM