Spaces in column value

Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default Spaces in column value

    I have a column table in which the values have spaces, i.e. "2005 CRA 696." In
    my query, I want to account for various ways people may type that number into a
    form, such as without any spaces - "2005CRA696" or with only "05CRA696." I
    cannot modify the structure of the table. Any suggestions?

    awhitaker Guest

  2. Similar Questions and Discussions

    1. Converting a 3 column pdf address list to a one column MS word doc
      I need to convert a 3 col pdf into a manipulable text doc. Acrobat gives me lots of ways to do this in the normal program, but it doesn't preserve...
    2. Column chart need column to exceed axis maximum value
      I need to figure out how to get a column in a columnchart to exceed the axis maximum or at least show at 100% height if it exceeds the axis maximum....
    3. Move bound column to right of dynamic column in datagrid?
      I have a datatable that I am binding to a C# ASP.NET 1.1 web page. I also want to put an "Edit" column on the datagrid. However, whenever I use...
    4. Convert an MS Access Yes/No column to a checkbox column in C# datagrid
      Currently I have a datagrid displaying the multiple columns of data (text and numerical) found in a table in MS Access. In the Access table,...
    5. how to Add different controls(textBox,DropDownList or some ) in the same column,based upon the value in the previous column (Say second Colum which contain dropdown with some values) ?
      I am new to ASP.NET. I am facing problem with datagrid. I will explain prob now. In the datagrid the first column is name in the second...
  3. #2

    Default Re: Spaces in column value

    Its not good practice to have spaces in a column name. It is better to use underscores or not at all .
    Abinidi Guest

  4. #3

    Default Re: Spaces in column value

    In a query, you can rename the column with an alias without the spaces. Make
    sure that you place the original column name within brackets (depending on your
    database). Something like this:

    SELECT [2005 CRA 696] AS 2005_CRA_696
    FROM yourtable....

    Phil

    paross1 Guest

  5. #4

    Default Re: Spaces in column value

    Thanks for your help, but I must not have been clear on my problem. The column
    name doesn't have a space - the values in the column have spaces, and I need to
    match those against user input that may or may not contain the same spaces.

    awhitaker Guest

  6. #5

    Default Re: Spaces in column value

    Are the spaces always in the same place? If so, use string functions on your form variable to create a new variable in the expected format. Use that format in your query.
    Dan Bracuk Guest

  7. #6

    Default Re: Spaces in column value

    Try to use this UDF for this purpose,

    <cffunction name="getCorrectFormat" output="true" returntype="string"
    access="public">
    <cfargument name="str" type="any" required="true"/>
    <cfset FirstFour=val(mid(str,1,4))>
    <cfset FirstFourLen=len(FirstFour)>
    <cfif FirstFourLen eq 1>
    <cfset FirstFour="200" & FirstFour>
    </cfif>
    <cfset LastThree=right(str,3)>
    <cfset newstr=trim(replacenocase(str,LastThree,"","all")) >
    <cfset MiddelThree=right(newstr,3)>

    <cfset correctformatStr=FirstFour & " " & MiddelThree & " " & LastThree>
    <cfreturn correctformatStr>
    </cffunction>


    <cfset str="05CRA696">
    <cfquery datasource="xyz" name=abc>
    select * from tablename where columnname='#getCorrectFormat(str)#'
    </cfquery>


    reenaroy Guest

  8. #7

    Default Re: Spaces in column value

    Just strip all whitespace out of the input and the value(s) from the table and compare the results. You can use a replace function or regular expressions.
    merrillaldrich Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139