[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

sql 2005 query spaces

Posted on 2008-01-29
5
Medium Priority
?
180 Views
Last Modified: 2010-04-21
hi i have a column called code where the data is stored as
code
a b
ab c
abc d
adc d
acb c

i want to write a query to show only the data before the spaces, i dont want any data after the spaces like
code
a
ab
abc
adc
acb

how can i get in using a sql query
0
Comment
Question by:romeiovasu
5 Comments
 
LVL 42

Expert Comment

by:dqmq
ID: 20773419
Select left(YourField+' ',Instr(YourField,' ')-1)...
0
 
LVL 13

Expert Comment

by:Ryan
ID: 20773438
There may be a more efficient way, but heres one I did real quickly.
It selects loc just to hold the location of the first space - kinda like a variable.

SELECT Left([teamname],IIf([loc],[loc],Len([teamname]))) AS Expr1, InStr(1,[TeamName],' ') AS loc
FROM tblTeams;
0
 
LVL 26

Accepted Solution

by:
ee_rlee earned 1500 total points
ID: 20787501
so that you won't have any errors when yourfield doesn't contain any spaces:

Select case when Instr(YourField,' ')>1 then left(YourField+' ', Instr(YourField,' ')-1) else YourField end as NoSpace
0
 

Author Closing Comment

by:romeiovasu
ID: 31426226
Thank you
0
 

Author Comment

by:romeiovasu
ID: 20792385
than k u
0

Featured Post

[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

Question has a verified solution.

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

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
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.
Suggested Courses

613 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