Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

SQL Uppercase First Char in Lastname using For XML Path?

Posted on 2014-02-12
3
Medium Priority
?
325 Views
Last Modified: 2014-02-12
This query never returns Cap (first char) when using 'For XML Path' in my example below.

Stuff ((SELECT Upper(Substring(ci.last_name, 1, 1)) + Lower(Substring(ci.last_name, 2,50))
	   FROM Contact_Info as ci
	   WHERE (ci.id = dbo.Contractors.id) FOR XML path('')), 1, 1, '') AS [LastNames]

Open in new window


Note: The same 'Upper/Lower' syntax work fine in this simple query:

SELECT Upper(Substring(ci.last_name, 1, 1)) + Lower(Substring(ci.last_name, 2,50))
FROM tblContact_Info as ci

Open in new window


Note: I've also used this function instead of the Upper syntax above, and it still returns ALL lowercase...

ALTER FUNCTION [dbo].[ProperCase]
(
  @string varchar(8000)
)
returns varchar(8000)
AS
   BEGIN
      set @string = lower(@string)
      declare @i int
      set @i = ascii('a')

while @i <= ascii('z')
begin

set @string = replace( @string, ' ' + char(@i), ' ' + char(@i-32))
set @i = @i + 1
end

set @string = char(ascii(left(@string, 1))-32) + right(@string, len(@string)-1)

return @string

End
go
grant execute on propercase to public
go
0
Comment
Question by:WorknHardr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 16

Accepted Solution

by:
Surendra Nath earned 2000 total points
ID: 39853207
the first method will still work, check out an example below
declare @t TABLE
(
LastNames VARCHAR(100)
)
INSERT INTO @T VALUES ('jack')
INSERT INTO @T VALUES ('jill')
INSERT INTO @T VALUES ('lincon')
INSERT INTO @T VALUES ('naruto')


SELECT STUFF(
(
SELECT ',' + Upper(Substring(LastNames, 1, 1)) + Lower(Substring(LastNames, 2,50)) 
FROM @T 
FOR XML PATH('')
),1,1,'')

Open in new window

0
 

Author Comment

by:WorknHardr
ID: 39853727
Wow, I was chopping-off the 1st char :)

Also works with a space like so: Stuff((SELECT ' ' + Upper(Substring.......

I'm trying to replace my Substring syntax for Stuff, seems a bit more friendly ...

Thanks
0
 

Author Closing Comment

by:WorknHardr
ID: 39853728
thx
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.

636 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