?
Solved

Truncate sql query results

Posted on 2009-12-31
2
Medium Priority
?
215 Views
Last Modified: 2012-05-08
If I have a query that returns a result of:

THIS IS THE RESULT

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

Accepted Solution

by:
Aneesh Retnakaran earned 1000 total points
ID: 26154912
SELECT LEFT ( ColumnName,  CHARINDEX(' ', ColumnName ) -1 )
0
 
LVL 60

Assisted Solution

by:Bill Prew
Bill Prew earned 1000 total points
ID: 26154950
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;

~bp
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
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…
SQL Database Recovery Software repairs the MDF & NDF Files, corrupted due to hardware related issues or software related errors. Provides preview of recovered database objects and allows saving in either MSSQL, CSV, HTML or XLS format. Ensures recov…
Stellar Phoenix SQL Database Repair software easily fixes the suspect mode issue of SQL Server database. It is a simple process to bring the database from suspect mode to normal mode. Check out the video and fix the SQL database suspect mode problem.

616 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