Solved

MS SQL 2008 - Complex Update Query

Posted on 2015-01-30
2
89 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

Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

Question has a verified solution.

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

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
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.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

615 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