Link to home
Start Free TrialLog in
Avatar of Karen Schaefer
Karen SchaeferFlag for United States of America

asked on

Using Declare variable within update statement

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

Avatar of lcohan
lcohan
Flag of Canada image

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%'
Avatar of Karen Schaefer

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of lcohan
lcohan
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks for the refresher - just a  little rusty.