473,624 Members | 2,234 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SQl Help - CHARINDEX on Multiple records

1 New Member
Join Date: May 2006
Posts: 6 Help - SQL Query Anaylzer

--------------------------------------------------------------------------------

Hi

I am using the following code to give me everything after a space in a field:

DECLARE @NM CHAR(30)
SET @NM = 'IMOGEN MASON'

SELECT SUBSTRING(@NM, CHARINDEX(' ', @NM) +1, LEN(@NM))
This code returns 'MASON' which is what I am after.

HOWEVER - I need to replace where it says 'Imogen Mason' with a field name so it repeats for each field in the table - there are nearly 3,000 rows so doing it indivisualy isnt an option.

I thought this would work:


DECLARE @NM CHAR(30)
SET @NM = (SELECT [NaME] FROM gola_stats)

SELECT SUBSTRING(@NM, CHARINDEX(' ', @NM) +1, LEN(@NM))


but I get an error that says: "Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression."
How do I repeat this for each row in my table? I then need to update another field with what the quyery returns (thats the easy bit)

Any help apreciated, thank you in advance!

Imogen
Jun 13 '06 #1
0 1560

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

Similar topics

5
41507
by: M Wells | last post by:
Hi All, Just wondering if it's any more efficient to use the following SQL statement to return a partial match from a column as opposed to the second statement. SELECT * FROM Table1 WHERE CHARINDEX('value', mycol) > 0 Versus:
2
8612
by: Little PussyCat | last post by:
Hello, I need to be able to replace only the first occurance of a space character in a column. Reason being is the data in the column I am trying to replace seems to have umpteen space characters after each entry, so a simple replace function will replace all the spaces after it with what I want! I have thought of RTRIM to get rid of the spaces after and then replace, I have also thought of CHARINDEX to find the first occurance of a...
5
42028
by: Willem | last post by:
Hello I am quite hopeless and of course a newbe. The situation: Sql2k / query I would like it ot break down the following string: 2004 Inventory:Ex.Plant Farm1:1st Cut:Premium:0094
3
5992
by: csomberg | last post by:
SQL Server 2000 Ya know, it is always the simplest stuff that gets ya !! I am having the hardest time getting a simple piece of code working. Must be brain dead today. Goal: Get the users full name from a string Here is sample data:
0
2256
by: prav78 | last post by:
hi there i have a field name(fil_srt_cond) with the values of cmpnt_name,ASC,1,2 cmpnt_stuff,DESC,2,3 i used the char index:- substring(BSSF.fil_srt_cond,charindex(BS.column_name,BSSF.fil_srt_cond) + LEN(BS.column_name) +1 ,3) ord,
1
2407
by: chudson007 | last post by:
I have a field containing a string with '/' in it multiple times. How can I return the charindex of the last occurance of '/' in the string? Regards, Ciarán
1
3676
by: db55 | last post by:
This script doesn't work. Why? UPDATE SET = LTRIM(SUBSTRING(, 1, convert(bigint, CHARINDEX(',', Comments)-1))) WHERE NOT( IS NULL) AND LEN() > 8 Basically, I'm trying to move everything before a comma into and everything after the comma into . The comments 2 script works. See below.
2
2999
by: matthewwhaley | last post by:
What is the best way to essentially use the charindex(find) function if the value is could be more than one variable (A or B or C) I can't seem to get an "or", "if" or "select if" to work Below is the code that works, I need 'GOV' to be either 'GOV' or 'FWD' or 'LIB' sqlstring = "SELECT Distinct substring(," _
7
3995
by: iritchie | last post by:
Hello all, I am trying to write a script which breaks down a single address field into individual fields, with char(10) or a carriage return as the delimiter. "empltable" is the table I am using, and "address" is the field I am looking to split. So far I have managed to: Split the field into 3
0
8681
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8341
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8488
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7170
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6112
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4084
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4183
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2611
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1488
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.