472,143 Members | 1,346 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,143 software developers and data experts.

SQl Help - CHARINDEX on Multiple records

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 1490

Post your reply

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

Similar topics

5 posts views Thread by M Wells | last post: by
2 posts views Thread by Little PussyCat | last post: by
5 posts views Thread by Willem | last post: by
3 posts views Thread by csomberg | last post: by
1 post views Thread by chudson007 | last post: by
reply views Thread by leo001 | last post: by

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.