Solved

Using Declare variable within update statement

Posted on 2014-04-04
4
175 Views
Last Modified: 2014-04-04
I need to change the text within a couple of records where the data contains the word "Annual" and change it to "Open"

declare @var1
@var1 = 'Open'

SELECT [ResourceSet]
      ,[ResourceType]
      ,[CultureCode]
      ,[ResourceKey]
      ,[ResourceValue]
      ,[Category]
      ,[Translated]
  FROM [bcdevtraining].[dbo].[cm_resource_core]
--UPDATE [bcdevtraining].[dbo].[cm_resource_core]
--   SET [ResourceValue] = 'Open Enrollment'
where [ResourceValue] like '%Annual Enrollment%'
GO
First record  = It's {0} &  @var1 &  'Enrollment through {1}. This is your opportunity to change your benefit elections, add or modify dependents, and change beneficiaries for {0}.
Second record = Begin Your Annual Enrollment Now!

Open in new window

0
Comment
Question by:Karen Schaefer
  • 2
  • 2
4 Comments
 
LVL 39

Expert Comment

by:lcohan
ID: 39978678
Why do you need to use variable if that's all you need to do and an update like you described (and enclosed below) will do what you need to:

UPDATE [bcdevtraining].[dbo].[cm_resource_core]
  SET [ResourceValue] = 'Open Enrollment'
where [ResourceValue] like '%Annual Enrollment%'
0
 

Author Comment

by:Karen Schaefer
ID: 39978684
Is there a Way to do a Mass update searching for all instances of "Annual Enrollment" and update the just that portion of the text with "Open Enrollment"?

K
0
 
LVL 39

Accepted Solution

by:
lcohan earned 500 total points
ID: 39978686
Sure and sorry my bad for the first posting - this must do it - use the REPLACE sql function

UPDATE [bcdevtraining].[dbo].[cm_resource_core]
  SET [ResourceValue] = replace([ResourceValue],'Annual Enrollment','Open Enrollment')
WHERE [ResourceValue]='%Annual Enrollment%'

OR you can reduce it to just the two words you mentioned:


UPDATE [bcdevtraining].[dbo].[cm_resource_core]
  SET [ResourceValue] = replace([ResourceValue],'Annual ','Open ')
WHERE [ResourceValue]='%Annual%'
0
 

Author Closing Comment

by:Karen Schaefer
ID: 39978754
thanks for the refresher - just a  little rusty.
0

Featured Post

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now