Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 11th, 2007, 12:34 PM
Registered User
 
Join Date: Dec 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Number formatting in SQL 2000

Hi,

I have a column of varchar 'numbers' and I would like to add leading zeros to ones that only have 3 numbers, ex. 703 = '0703'. Is there a quick update table statement I could write (psuedo code below):

if cell.text.num_chars = 3
  then '0' + cell.text

Thanks!

~Matt
 
Old December 11th, 2007, 12:47 PM
Registered User
 
Join Date: Dec 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I guess I really mean text formatting then... :)

 
Old December 11th, 2007, 01:12 PM
Registered User
 
Join Date: Dec 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I figured it out, so no need to reply.

update TABLE set Column_A='0'+ Column_A from TABLE where COLUMN_A not like '0%' and len(COLUMN_A) = 3

 
Old December 11th, 2007, 01:16 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
Default

UPDATE Table
Set varcharNumbers = RIGHT(('000' + varcharNumbers),4)






Similar Threads
Thread Thread Starter Forum Replies Last Post
Number formatting / RegExp pierre.voisin Javascript 0 March 3rd, 2008 01:50 PM
generate Random number in MS SQL server 2000 nax111 SQL Server 2000 9 March 29th, 2007 10:14 PM
formatting number vkey XSLT 1 June 22nd, 2005 02:29 AM
formatting number dhol General .NET 2 February 24th, 2005 12:47 PM
Formatting a number eelisMX Pro VB.NET 2002/2003 7 January 28th, 2005 05:22 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.