[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 92
  • Last Modified:

MS SQL 2008 - Complex Update Query

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
RavenTim
Asked:
RavenTim
1 Solution
 
SimonCommented:
UPDATE Customer
set AcctCode='BMR'+RIGHT(custno,4), ContractNo='BMR'+RIGHT(custno,4)

Open in new window

0
 
RavenTimAuthor Commented:
Perfect!  Thanks Simon!
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now