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 August 17th, 2004, 08:13 AM
Authorized User
 
Join Date: Jun 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default The "Right" command & zero filling the data

Hi everyone, I have a problem and I need some help.

We are using SQL to format data in tables in preparation for uploading to another system. The other system requires that numeric data be zero filled for uploading with no decimal places, so 192.30 will become 0000019230 .

In access I used to be able to "pad" the data using something like the following:-

UPDATE DISTINCTROW [rec26 1] SET [rec26 1].[dd2683,1] = Right("000000000" & [rec26 1].[dd2683,1],9), [rec26 1].[dd2686,1] = Right("000000000" & [rec26 1].[dd2686,1],9);

Obviously in SQL, can't use "&" for something like this so I thought "+" would be the solution. It just doesn't seem to do anything.

Can anyone shed some light on this issue

Many thanks

 
Old August 17th, 2004, 05:13 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

What is the datatype of the field that contains values with decimals? 192.30

_________________________
- Vijay G
Strive for Perfection
 
Old August 18th, 2004, 09:43 AM
Authorized User
 
Join Date: Jun 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The field I am trying to update is a char field. Don't worry about the source field as that is a decimal from another table altogether, and therefore not part of the problem.

 
Old August 18th, 2004, 11:21 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

You can do that in SQL also, I've done something like:

right('0000000000' + replace(convert(char, [rec26 1]), '.', ''), 10)

Just tested this out in my DB and it works in SQL Server.

Brian
 
Old August 18th, 2004, 09:29 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

You can try this too, as an alternative.
Code:
Replace(replicate('0',10-len([rec26 1])) + [rec26 1],'.','')
OR
Code:
replicate('0',9-len(replace([rec26 1],'.',''))) + replace([rec26 1],'.','')
Cheers!

_________________________
- Vijay G
Strive for Perfection





Similar Threads
Thread Thread Starter Forum Replies Last Post
filling the combobox using sql data adapter kumaran BOOK: Professional .NET 2.0 Generics 4 October 5th, 2015 07:57 AM
prob in Data Environment & Command Rajesh Pachouri Pro VB Databases 0 September 20th, 2006 01:33 AM
filling a combo box from a data object allee_man Beginning VB 6 1 March 1st, 2005 08:08 AM
Data Filling error after Relation melvik ADO.NET 2 December 29th, 2004 06:19 PM
Filling in a list box with data from Access goplayoutside VB Databases Basics 7 April 21st, 2004 08:27 PM





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