Skip to main content
April 20, 2006
Answered

using trim with SQL

  • April 20, 2006
  • 2 replies
  • 458 views
I've attempted to use trim() im my SQL statement but It throws an error saying its not a valid function.

This isnt the statement but this is the context im using it in.

<cfquery datasource="#datasources.DATADSN#">
INSERT INTO dbo.People (Christian)
<cfif IsDefined("FORM.Christian") AND #FORM.Christian# NEQ "">
trim('#FORM.Christian#')
<cfelse>
NULL
</cfif>
</cfquery>

If you cant use it at this point, where can you use it?
    This topic has been closed for replies.
    Correct answer drforbin1970
    If you are just trying to trim leading/trailing whitespace, here is the correct syntax:

    <cfquery datasource="#datasources.DATADSN#">
    INSERT INTO dbo.People (Christian)
    <cfif IsDefined("FORM.Christian") AND Trim(FORM.Christian) NEQ "">
    #Trim(FORM.Christian)#
    <cfelse>
    NULL
    </cfif>
    </cfquery>

    2 replies

    drforbin1970Correct answer
    Inspiring
    April 20, 2006
    If you are just trying to trim leading/trailing whitespace, here is the correct syntax:

    <cfquery datasource="#datasources.DATADSN#">
    INSERT INTO dbo.People (Christian)
    <cfif IsDefined("FORM.Christian") AND Trim(FORM.Christian) NEQ "">
    #Trim(FORM.Christian)#
    <cfelse>
    NULL
    </cfif>
    </cfquery>
    April 20, 2006
    It looks like you're using SQL Server. SQL Server 2000 doesn't have a unified trim function, you need to left and right-trim. Try LTrim ( Rtrim ('#FORM.Christian#')).