Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

MS SQL 2008 - Complex Update Query

Posted on 2015-01-30
2
Medium Priority
?
90 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 2000 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

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

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

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…
I have a large data set and a SSIS package. How can I load this file in multi threading?
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

704 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