Solved

MS SQL 2008 - Complex Update Query

Posted on 2015-01-30
2
87 Views
Last Modified: 2015-01-30
I need to update two fields for each row in a table in my database.  Here's the layout:

Table name - "Customer"
Columns involved - "Custno" (varchar(10))
                                 - "AcctCode" (varchar(50))
                                 - "ContractNo" (varchar(30))

All of the Custno fields contain five digits, starting with a zero (0).  All of the AcctCode & ContractNo fields are empty.  I need to populate both the AcctCode & ContractNo fields with "BMR" and then the right 4 digits of the Custno field.  For example:

An account with Custno "01012", the AcctCode & ContractNo fields should be populated to read "BMR1012".
An account with Custno "02044", the AcctCode & ContractNo fields should be populated to read "BMR2044", etc...
0
Comment
Question by:RavenTim
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 18

Accepted Solution

by:
Simon earned 500 total points
ID: 40580924
UPDATE Customer
set AcctCode='BMR'+RIGHT(custno,4), ContractNo='BMR'+RIGHT(custno,4)

Open in new window

0
 

Author Closing Comment

by:RavenTim
ID: 40580944
Perfect!  Thanks Simon!
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

696 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