Truncate sql query results

Posted on 2009-12-31
Last Modified: 2012-05-08
If I have a query that returns a result of:


and I only want the first word "THIS", how do I go about writing a query to do this.
Question by:tsmit877
    LVL 75

    Accepted Solution

    SELECT LEFT ( ColumnName,  CHARINDEX(' ', ColumnName ) -1 )
    LVL 51

    Assisted Solution

    by:Bill Prew
    If you just want the first 4 characters then you can do something like:

    select substring(col1, 1, 4) from table1;

    if you want the entire first word then you can do something like this:

    select substring(col1, 1, charindex(' ', col1)-1) from table1;


    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

    So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
    In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
    This video discusses moving either the default database or any database to a new volume.
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    745 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

    15 Experts available now in Live!

    Get 1:1 Help Now