The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Databases
> MS SQL Development
|
Removing white space from list of names
Discuss Removing white space from list of names in the MS SQL Development forum on Dev Shed. Removing white space from list of names MS SQL Development forum discussing administration, MS SQL queries, and other MS SQL-related topics. SQL Server is Microsoft's enterprise database engine.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

May 7th, 2012, 01:07 PM
|
|
Registered User
|
|
Join Date: May 2012
Posts: 4
Time spent in forums: 1 h 1 m 37 sec
Reputation Power: 0
|
|
|
Removing white space from list of names
I work for a school district and we have a need of exporting data from our SQL 2005 database. Often a student’s first or last name may contain a space. Unfortunately, the software into which we are importing the data does not allow for white space. After a bit of research I found the REPLACE command.
For example SELECT REPLACE (@NewFirstName,‘ ‘,’’) But this variable only works for a single name. How do I tell SQL to find the space and replace it with no space for a whole list of student names?
Thank you in advance -
David
|

May 7th, 2012, 06:48 PM
|
 |
SQL Consultant
|
|
Join Date: Feb 2003
Location: Toronto Canada
|
|
Quote: | Originally Posted by walkerSGUSD How do I tell SQL to find the space and replace it with no space for a whole list of student names? | exactly the same way, except with a column like students.student_name, instead of a variable like @NewFirstName
also, you have to use single quotes (next to the enter key on most keyboards) rather than those wonky microsoft "smart quotes" (a misnomer if ever there was one)
|

May 9th, 2012, 06:23 PM
|
|
Registered User
|
|
Join Date: May 2012
Posts: 4
Time spent in forums: 1 h 1 m 37 sec
Reputation Power: 0
|
|
|
Thank you, Rudy, for your reply. That makes sense. However, when I run this
SELECT replace (STU.FN, ' ', '')
(i did use single quotes)
SQL responds with
Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "STU.FN" could not be bound.
Do you have any suggestions? thanks again -
David
|

May 9th, 2012, 08:53 PM
|
 |
SQL Consultant
|
|
Join Date: Feb 2003
Location: Toronto Canada
|
|
Quote: | Originally Posted by walkerSGUSD Do you have any suggestions? | i'd have to see the entire sql statement
|

May 10th, 2012, 11:35 AM
|
|
Registered User
|
|
Join Date: May 2012
Posts: 4
Time spent in forums: 1 h 1 m 37 sec
Reputation Power: 0
|
|
|
that was it ! :-)
|

May 10th, 2012, 12:59 PM
|
 |
SQL Consultant
|
|
Join Date: Feb 2003
Location: Toronto Canada
|
|
Quote: | Originally Posted by walkerSGUSD that was it ! :-) |
you mean this? --
Code:
SELECT replace (STU.FN, ' ', '')
it seems you've omitted the FROM clause
|

May 10th, 2012, 02:18 PM
|
|
Registered User
|
|
Join Date: May 2012
Posts: 4
Time spent in forums: 1 h 1 m 37 sec
Reputation Power: 0
|
|
|
whoops - my mistake, much better now :-) thank you again
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|