| Author |
Topic |
|
mase2hot
Starting Member
36 Posts |
Posted - 2010-04-25 : 15:23:09
|
| I have a few columns that when I enter data into my table that I want upper to run on them would I have it as a trigger? If so how would I lay it out for multiple colums? I presume the below wouldnt work...ThanksUPDATE tax.dbo.Clients SET Postcode = UPPER(Postcode)UPDATE tax.dbo.Clients SET NT_NUMBER = UPPER(NT_NUMBER) |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
mase2hot
Starting Member
36 Posts |
Posted - 2010-04-25 : 15:35:02
|
| I know the code works but I want it to automatically run this code so I dont need to. Soory I dont get what you mean by check constraint or always UPPER it on disply? |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2010-04-25 : 15:39:48
|
| A check constraint is an object that you can put on a column to protect the data. If the incoming data doesn't follow the check constraint rule, then an error is returned. You could just run UPPER on your SELECT statements when getting the data out of the table, that way it is always in uppercase and you don't need to worry how it is stored. To automatically uppercase the data though, a trigger is a good way to do it.Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Subscribe to my blog |
 |
|
|
mase2hot
Starting Member
36 Posts |
Posted - 2010-04-25 : 16:16:13
|
| my data is linked to ms access so I guess I'll make a trigger for it. Can I simply put the statements side by side in the trigger like I have in the first post? |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-04-25 : 17:36:39
|
You don't need two statements.UPDATE tax.dbo.Clients SET Postcode = UPPER(Postcode), NT_NUMBER = UPPER(NT_NUMBER) No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
pk_bohra
Master Smack Fu Yak Hacker
1182 Posts |
Posted - 2010-04-26 : 00:09:17
|
| Since you are using 2008 (as the post is in 2008 forum) you can use the computed column directly.Just try the below example to get more ideaCreate table UpperTest(Srno int identity, Sname varchar(50), UpperSname as Upper(Sname)) Insert into UpperTest (Sname) Select 'TestName' Select * from UpperTestRegards,BohraI am here to learn from Masters and help new bees in learning. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-04-26 : 00:53:51
|
| I really cant understand the reason behind storing the upper case equivalent of a column data in another column inside the table. Isnt this a presentation issue which can very easily achieved at front end using formatting functions. Is it to necessary to duplicate all data in a column for this purpose?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
mase2hot
Starting Member
36 Posts |
Posted - 2010-04-26 : 18:19:07
|
| I tried the code below with no joy, I get error:Msg 8197, Level 16, State 4, Procedure UPPER_COLUMNS, Line 1The object 'dbo.Clients' does not exist or is invalid for this operation.CREATE TRIGGER UPPER_COLUMNSON dbo.ClientsAFTER INSERTAS BEGINUPDATE tax.dbo.Clients SET Postcode = UPPER(Postcode), NT_NUMBER = UPPER(NT_NUMBER)END |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
mase2hot
Starting Member
36 Posts |
Posted - 2010-04-26 : 18:49:18
|
| Hi I did,and get error: Msg 8197, Level 16, State 4, Procedure UPPER_COLUMNS, Line 1The object 'dbo.Clients' does not exist or is invalid for this operation.CREATE TRIGGER UPPER_COLUMNSON dbo.ClientsAFTER INSERTAS BEGINUPDATE cSET Postcode = UPPER(i.Postcode), NT_NUMBER = UPPER(i.NT_NUMBER)FROM dbo.Clients cJOIN inserted iON c.ID = i.IDEND |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
mase2hot
Starting Member
36 Posts |
Posted - 2010-04-27 : 16:53:40
|
| Thanks, yeah I wasnt on the correct database! |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
DBA in the making
Aged Yak Warrior
638 Posts |
Posted - 2010-04-27 : 17:24:06
|
quote: Originally posted by mase2hot Thanks, yeah I wasnt on the correct database!
------------------------------------------------------------------------------------Any and all code contained within this post comes with a 100% money back guarantee. |
 |
|
|
|