views:

55

answers:

2

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?

+6  A: 

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.

Daniel Vandersluis
It still doesn't work, which means that there is an underlying problem that I haven't fixed. At least I can rule out it being a simple syntax error.
thursdaysgeek
thursdaysgeek, what still doesn't work? Left is a very simple function, and it works fine. What **exactly** are you attempting to achieve, and how are you determining that something isn't working?
Peter Boughton
It's pretty complex code, not mine, and I don't understand it. I was trying to limit how many characters were being inserted, which appears to be killing the query. It seems like it is submitting more characters than the table can handle, but I don't know if that is REALLY the problem. I can only check by seeing if the right number of records are saved. The query is still dying, somewhere. With the syntax correct at this point, but the same overall behaviour, that means I'm not even at the root of the problem yet. I'm sorry, it's hard to explain what you don't really understand. :(
thursdaysgeek
A: 
<cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#left(listItems[i].itemName,100)#" />

Your hashtags were in the wrong place and you were missing a closing parenthesis.

Al Everett
Oops, I messed up that second example. That should have given me a syntax error, too.
thursdaysgeek