Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Make column in table uppercase

Author  Topic 

taunt
Posting Yak Master

128 Posts

Posted - 2014-01-16 : 14:05:38
Hello is there a way to make everything in a column uppercase? We have a vendor table and the name field has mix case results. I would like to make it where everything is all uppercase, but had no clue on how to do that in SQL.

djj55
Constraint Violating Yak Guru

352 Posts

Posted - 2014-01-16 : 14:50:57
If it is one time run an UPDATE :
UPDATE mytable SET ColumnName = UPPER(ColumnName);


djj
Go to Top of Page

ScottPletcher
Aged Yak Warrior

550 Posts

Posted - 2014-01-16 : 16:44:07
You can add a trigger than automatically always forces the column to be all upper case.


CREATE TRIGGER tablename_trg_name_force_upper
ON dbo.tablename
AFTER INSERT, UPDATE
AS
SET NOCOUNT ON
UPDATE t
SET name = UPPER(t.name)
FROM dbo.tablename t
INNER JOIN inserted i ON
i.key_col = t.key_col
WHERE
NOT EXISTS(SELECT 1 FROM deleted) OR
UPDATE(name)
GO

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2014-01-17 : 07:02:13
why do you need to do this? So far as your database collation is case insensitive there's no need for this at all!
And if its for front end display requirement, there are formatting functions available in all front end languages for doing this.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2014-01-27 : 07:07:48
You can make it upper while Selecting data from that table using SELECT statement

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

djj55
Constraint Violating Yak Guru

352 Posts

Posted - 2014-01-27 : 14:37:58
Yes.
SELECT UPPER(yourcolumn) AS YourColumnName FROM YourTable


djj
Go to Top of Page
   

- Advertisement -