Syntax for ColdFusion Left() function
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.
精彩评论