I am writing a report using report builder and the one of the filed value of the data set is in upper-case I want to capitalize first letter of this data field value in the text box. Please let me know if you could help.
Thanks Yogi
I'm assuming you're using a query from the database to fetch your data through a connection object. Based on what you've said here, a reasonable approach would be:
SELECT UPPER(LEFT([FIELD],1))+LOWER(SUBSTRING([FIELD],2,LEN([FIELD])))
If you have more than one word in your data, you will have to create a UDF to handle to pascal casing:
CREATE FUNCTION [dbo].[pCase]
(
@strIn VARCHAR(255)
)
RETURNS VARCHAR(255)
AS
BEGIN
IF @strIn IS NULL
RETURN NULL
DECLARE
@strOut VARCHAR(255),
@i INT,
@Up BIT,
@c VARCHAR(2)
SELECT
@strOut = '',
@i = 0,
@Up = 1
WHILE @i <= DATALENGTH(@strIn)
BEGIN
SET @c = SUBSTRING(@strIn,@i,1)
IF @c IN (' ','-','''')
BEGIN
SET @strOut = @strOut + @c
SET @Up = 1
END
ELSE
BEGIN
IF @up = 1
SET @c = UPPER(@c)
ELSE
SET @c = LOWER(@c)
SET @strOut = @strOut + @c
SET @Up = 0
END
SET @i = @i + 1
END
RETURN @strOut
END
And then utilise the function like so:
SELECT DBO.PCASE([FIELD])