Showing posts with label caps. Show all posts
Showing posts with label caps. Show all posts

Sunday, March 11, 2012

Convert to caps ?

Hai,

This is my table ?

Table1

hyundai

Laptop

Samsung

onida-tv

How to convert all these values to caps .

Table1

HYUNDAI

LAPTOP

SAMSUNG

ONIDA-TV

UPDATE Table SET column = UPPER(column);

Convert Text pulled from SQL databse to UPPER and lower, etc

I'm still haven't resolved the issue with displaying information from a SQL database. The text I'm displaying is in ALL CAPS in the SQL database, and I'm trying to convert it so that when I display it in gridview, The First Letter Of Each Word Is Capitalized, as apposed to ALL CAPS. I've tried the text-transform feature of CSS, but I noticed in a SQL book there are LOWER() & UPPER() string functions. The ideal thing to do then, would be to do some select statement that converts all the incoming text to lowercase, then use the CSS text-transform: capitalize , to convert the first letter of each word to caps.

Basically, I need a select statement or something that converts my sql material to lowercase. Thanks.

There is a Lower() function in SQL Server 2005. Use it like this:

SELECT Lower( ColumnName ) FROM TableName

|||

Here is a function I'm using to format a string so that each char become lowercase except the first chars of all words:


CREATE FUNCTION fn_FormatName (@.name VARCHAR(8000))
RETURNS VARCHAR(8000)
AS
BEGIN
DECLARE @.tempStr VARCHAR(8000),@.p INT,@.tempWord VARCHAR(8000),@.Words VARCHAR(8000)
IF (LEN(@.name)=1)
RETURN UPPER(@.name)

ELSE
BEGIN
SELECT @.tempStr=LOWER(@.name),@.p=1,@.Words=''
IF (CHARINDEX(' ',@.tempstr,@.p)=0)
SET @.Words= UPPER(LEFT(@.tempStr,1))+SUBSTRING(@.tempStr,2,LEN(@.tempStr))
ELSE
BEGIN
WHILE (@.p<=LEN(@.tempstr) AND CHARINDEX(' ',@.tempstr,@.p)>0)
BEGIN
SET @.tempWord=SUBSTRING(@.tempstr,@.p,CHARINDEX(' ',@.tempstr,@.p)-@.p+1)
SET @.Words=@.Words+(UPPER(LEFT(@.tempWord,1))+SUBSTRING(@.tempWord,2,LEN(@.tempWord)))
SET @.p=CHARINDEX(' ',@.tempstr,@.p)+1
END
SET @.tempWord=SUBSTRING(@.tempstr,@.p,LEN(@.tempstr))
SET @.Words=@.Words+(UPPER(LEFT(@.tempWord,1))+SUBSTRING(@.tempWord,2,LEN(@.tempWord)))
END
END
RETURN @.Words
END
go

SELECT dbo.fn_FormatName('CHONG VINCENT DDF')