Solved

SQL update statement based on a formula?

Posted on 2014-03-18
2
294 Views
Last Modified: 2014-03-18
in my table PostalCodes i need to select all Postalcodes from dbo.postalcodes where LEN = 4, and then add a leading 0 (zero) in front of value and re-update it.

For example, postal codes in the table that look like this:  7712  should actually be 07712

Anyone know how to do this?
0
Comment
Question by:arthurh88
[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 40

Accepted Solution

by:
Kyle Abrahams earned 500 total points
ID: 39938704
update postalcodes
set postalcode = '0' + postalcode
where len(postalcode) = 4
0
 

Author Comment

by:arthurh88
ID: 39938719
bah!  i should have figured this one out :)  Thanks!!
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Question about Common Table Expressions 3 45
Creating a View from a CTE 15 50
T-SQL: need to reset a declared variable 4 33
Datatable / Dates ? 4 33
I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

752 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