473,466 Members | 1,455 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Select the first string

ddtpmyra
333 Contributor
I wanted to select the first word before spaces.

ex.
Science 101


result:
Science
Apr 7 '11 #1

✓ answered by Rabbit

Append/concatenate a space.
subject + ' '

7 6225
Rabbit
12,516 Recognized Expert Moderator MVP
You can find the first space using CHARINDEX() and then use LEFT() to get those first characters.
Apr 7 '11 #2
ddtpmyra
333 Contributor
can you give me the whole sample syntax using both?
Apr 7 '11 #3
ddtpmyra
333 Contributor
I use the sytax below but it didn't pick subject names with one work only.

ex.
science 101
history
science 102
biology
physical education

result:
science
science
physical

what I wanted is to select all but take out the 2nd word after a space

result wanted:
science
history
science
biology
physical


Expand|Select|Wrap|Line Numbers
  1. SELECT subject, ltrim(Left(subject, CHARINDEX(' ', subject)))FROM dapdata
Apr 7 '11 #4
Rabbit
12,516 Recognized Expert Moderator MVP
Append a space to the end of subject before using charindex.
Apr 7 '11 #5
ddtpmyra
333 Contributor
sorry rabbit i cannot understand what to do, can you help by re-writing my sql statement? i would appreciate it! :)
Apr 7 '11 #6
Rabbit
12,516 Recognized Expert Moderator MVP
Append/concatenate a space.
subject + ' '
Apr 7 '11 #7
ddtpmyra
333 Contributor
it works! thanks Rabbit!
Expand|Select|Wrap|Line Numbers
  1. SELECT subject, ltrim(Left(subject, CHARINDEX(' ',subject + ' ' )))FROM dapdata 
Apr 7 '11 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Mike R | last post by:
Hi, I have a table called opportunity, included within this table are a opclosed (date) , a companyid (integer) and some other columns. There are many opportunity records per companyid . I am...
10
by: MLH | last post by:
A97 incorporates a new twist on the use of db-clik. If you use A97, you know what I mean. Maybe it deserves explanation... Let's say you have a macro and you open it to browse. Lets say it has...
0
by: isel77 | last post by:
Hi, I get a null reference exception while accessing the first row returned by a Select in a DataTable of a DataSet (typed) stored in cache ( datatable.Select( "FieldX=1" ) ). The error occurs...
2
by: Andrew Lias | last post by:
Let us say that I have a table with two sets of values as such: Item Extension --- ---- 100023 1 100025 1 100025 2 100028 1 100029 1 100029 2
2
by: lekshminair | last post by:
hello friends, can u help me. how to print first string in a line.(before first space) for example: String str={"Hello world java"} output Hello
5
tolkienarda
by: tolkienarda | last post by:
hi all i need to select the first fifteen words of an article stored in a mysql database. so i have the basic idea laid out but the exact syntax seems a bit confusing. i have a book here on...
0
by: =?Utf-8?B?Q2FibGVHdXk=?= | last post by:
If I have an unsorted listview I know I can select the first Item by ListView.Items.Selected = true. How do I select the first item in a sorted listview? Thanks. CableGuy
1
jamesd0142
by: jamesd0142 | last post by:
Hi i want to select the first row only in my table... i have this: declare @abc varchar(2000) set @abc = (select Sql_Table_Name from temptable10) print @abc how can i edit it to only...
1
by: Cyprus106 | last post by:
So I've got about a million records that I'm sifting through with a SELECT statement. Right now I've been saying SELECT * FROM MYTABLE WHERE MYFIELD='GUIDE'... But I only want the first record it...
5
by: eko99312 | last post by:
Pardon me if this question already been asked before. I tried to sort a query to meet my desire. Here is the example: Date Customer Supplier Price 31-Oct-09 Charlie Australia $ 100...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.