Solved

sql query spaces

Posted on 2007-11-29
4
229 Views
Last Modified: 2010-03-19
hi all i have my data like this
MP1M A
QX31 S
MP1M A
FA20 S
FA20 S
PTTF      P        F
FN3NM0014 P        S
FN3NM0014 P        S
FN3NM0014 S        S
FN3NM0014 S        S
FN3NM0014 S        S
FN3NM0014 S        S

i want to remove all the data after the first space. i dont want anything after the first space.  how can i write a query the filed name for this "billcode"  

0
Comment
Question by:romeiovasu
  • 2
4 Comments
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 500 total points
Comment Utility
SELECT LEFT(urColumn, CHARINDEX(' ', urColumn)-1 )
0
 

Author Comment

by:romeiovasu
Comment Utility
aneesh how do you do this in access
0
 
LVL 8

Expert Comment

by:digital_thoughts
Comment Utility
All you need to do is find the index (location) of the first space and if it does exist, then do a LEFT on that length:

SELECT
      LEFT(billcode, CASE WHEN CHARINDEX(' ', billcode) = 0 THEN LEN(billcode) ELSE CHARINDEX(' ', billcode) END) AS billcode
FROM
      TableName
0
 

Author Comment

by:romeiovasu
Comment Utility
how to do the same thing in access
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

763 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

9 Experts available now in Live!

Get 1:1 Help Now