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 2005 Forums
 Transact-SQL (2005)
 Update part of a field

Author  Topic 

sross81
Posting Yak Master

228 Posts

Posted - 2008-10-31 : 10:50:10
Hello,

I have a table called Triggers that has has a column called field. In this column there is text like this:

Triggers: (not all columns but the ones that I need to work with)
Template_id,Field
50,Lab_master_.PT_PTT
50, Lab_master_.T3_total_dx
50, Lab_Master_.T3_update1

There are a whole bunch of different fields all varying in length but they all have Lab_master_ in front of the (.) What I want to be able to do is update just the word Lab_master_ with CHC_Lab_Master_ but leave the rest after the (.) as is. Is there a way to do this?

Update Trigger
Set Field = CHC_Lab_Master
where template_id = 50 and field = 'Lab_master_%'

I am not sure how to do it since there are extra values that don't need to be updated in the field name??



Thanks in Advance!
Sherri

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-31 : 10:53:03
[code]
Update Trigger
Set Field =STUFF(Field,1,CHARINDEX('.',Field)-1,'CHC_Lab_Master')
where template_id = 50 and field like 'Lab_master_%'
[/code]
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-10-31 : 10:53:45

Update Trigger
Set Field = replace(Field,'Lab_master_ ','CHC_Lab_Master_')
where template_id = 50 and field like 'Lab_master_%'


Madhivanan

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

sross81
Posting Yak Master

228 Posts

Posted - 2008-10-31 : 11:06:35
Thanks this works. :)

quote:
Originally posted by visakh16


Update Trigger
Set Field =STUFF(Field,1,CHARINDEX('.',Field)-1,'CHC_Lab_Master')
where template_id = 50 and field like 'Lab_master_%'




Thanks in Advance!
Sherri
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-31 : 11:07:47
Cheers
Go to Top of Page
   

- Advertisement -