Solved

MS SQL 2008 - Complex Update Query

Posted on 2015-01-30
2
81 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
2 Comments
 
LVL 18

Accepted Solution

by:
SimonAdept earned 500 total points
Comment Utility
UPDATE Customer
set AcctCode='BMR'+RIGHT(custno,4), ContractNo='BMR'+RIGHT(custno,4)

Open in new window

0
 

Author Closing Comment

by:RavenTim
Comment Utility
Perfect!  Thanks Simon!
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

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.
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…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

744 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

19 Experts available now in Live!

Get 1:1 Help Now