Remove Spaces from items pulled from SQL Table.

Posted on 2006-05-23
Last Modified: 2012-05-05
Remove Spaces from items pulled from SQL Table.

I have Model and Serial numbers that some spaces at the begaining and end.  I need to show the vales on screen so we can print them with barcodes.  Beacause of spaces this does not work.

 dim dia, strSQL, rs, strSQL1, rs1, ordno, strSQL2, rs2, strSQL3, rs3, strSQL4, rs4, znToAdd, strSQL5, srl
ordno= Request.QueryString("ordno")
  strSQL = "SELECT * FROM sfordfil_sql where ord_no like '" & ordno & "'"
  set rs = Conn.Execute(strSQL)
  strSQL2 = "SELECT * FROM labels_typ WHERE item_no = '" & rs("item_no") & "'"
  set rs2 = Conn.Execute(strSQL2)
      MODEL ID#: <%=rs2("mdl_detail")%><br>
      <font face="IDAutomationC39XS" size="3">*<%=rs2("mdl_detail")%>*</font><br>

Question by:kwitcom
    LVL 50

    Assisted Solution

    you need to tell use the database system you are using  for us to give the correct syntax...

    SQL Server

    use LTRIM(RTRIM(your Column))


    use STRIP(yourCOlumn,B,' ')       (mainframe ver 6&7)
    or TRIM(yourColumn,B,' ')

    LVL 50

    Expert Comment

    many dbms also have a replace function which would allow you to remove all spaces ....

    but that would remove internal spaces as well.

    Author Comment

    MS SQL, from a ASP page.  I don't want to change the data in the table.  just the output of it.
    LVL 8

    Expert Comment

    MS SQL doesnt have a trim function, but lowfat's LTRIM(RTRIM(your Column)) should work. If you use this in a select query it will only trim the query output, not the data in the table.

    Author Comment

    Where in my Query line do I put it?

      strSQL2 = "SELECT * FROM labels_typ WHERE item_no = '" & rs("item_no") & "'"

    LVL 50

    Accepted Solution

    you need to specifically specify the column names you want returned...


    strSQL2 = "SELECT col1,ltrim(rtrim(serial)) as serial,ltrim(rtrim(model)) as model,col3,col4,... FROM labels_typ WHERE item_no = '" & rs("item_no") & "'"

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
    Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
    Video by: Steve
    Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now