开发者

Syntax for ColdFusion Left() function

开发者 https://www.devze.com 2023-01-13 23:20 出处:网络
I have a SQL statement, in ColdFusion, and I want to limit the size of one field.Neither of the following appear to work (they don\'t give errors, they just don\'t limit the field).

I have a SQL statement, in ColdFusion, and I want to limit the size of one field. Neither of the following appear to work (they don't give errors, they just don't limit the field).

INSERT INTO ListItems
VALUES ('#qGetListID.ID#',
      <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#listItems[i].itemID#" />,
      <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="left(#listItems[i].itemName#,100)" />开发者_运维技巧;)

and

INSERT INTO ListItems
VALUES ('#qGetListID.ID#',
      <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#listItems[i].itemID#" />,
      left(<cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#listItems[i].itemName#" />,100))

How can I limit that last field to only 100 characters?


Your syntax is correct, but you need to put the whole thing inside #...#:

INSERT INTO ListItems
VALUES ('#qGetListID.ID#',
      <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#listItems[i].itemID#" />,
      <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#left(listItems[i].itemName,100)#" />)

Otherwise, CF will only evaluate the part within hashes, and the rest of the value will be taken as-is.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号