Solved

Using Declare variable within update statement

Posted on 2014-04-04
4
176 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
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.

911 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

24 Experts available now in Live!

Get 1:1 Help Now