473,394 Members | 1,750 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

casting and padding problem

hello,

update trl_info
set rec_count = repeat('0', 11- Length(cast((select count(*) from
tableA) as char(5))))
concat cast((select count(*) from tableA) as char(5))

The problem is the that value of count(*) may be big or smaller than 5
characters long so how to dynamically change the casting of the
interger to a char that is the same length of the count(*) size so
that the right of amount of leading '0's will be added for a total
character length of 11.

Thanks

WofD
Nov 12 '05 #1
3 6060
I have no idea how to dynamically change the casting but I got the
result (UDB 8.1 FP7) you want with:

substr(right('00000000000'||digits(count(*)),11),1 ,11)

1. "count(*)" - Count the number of rows
2. "digits" - Convert to a string with leading zeros
3. "||" - Concatenate 11 zeros onto the front of the result
4. "right" - Use only the rightmost 11 characters
(The following is needed for command line usage to truncate the
generated string. You may need it too.)
5. "substr" - Use only the first 11 characters of the string

This also has the advantage of performing the count only once. I leave
it to you to code this as a "case" statement to insert the correct
number of leading zeros.

Phil Sherman
Thanos wrote:
hello,

update trl_info
set rec_count = repeat('0', 11- Length(cast((select count(*) from
tableA) as char(5))))
concat cast((select count(*) from tableA) as char(5))

The problem is the that value of count(*) may be big or smaller than 5
characters long so how to dynamically change the casting of the
interger to a char that is the same length of the count(*) size so
that the right of amount of leading '0's will be added for a total
character length of 11.

Thanks

WofD


Nov 12 '05 #2
would this do the trick??

update trl_info
set rec_count = repeat('0', 11- Length(ltrim((cast((select count(*) from
tableA) as char(5))))))
concat ltrim(cast((select count(*) from tableA) as char(11)))

in******@hotmail.com (Thanos) wrote in message news:<ea**************************@posting.google. com>...
hello,

update trl_info
set rec_count = repeat('0', 11- Length(cast((select count(*) from
tableA) as char(5))))
concat cast((select count(*) from tableA) as char(5))

The problem is the that value of count(*) may be big or smaller than 5
characters long so how to dynamically change the casting of the
interger to a char that is the same length of the count(*) size so
that the right of amount of leading '0's will be added for a total
character length of 11.

Thanks

WofD

Nov 12 '05 #3
How about this?
update trl_info
set rec_count = DIGITS(CAST((select count(*) from tableA) AS INTEGER))
Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Alex Vinokur | last post by:
"Richard Bos" <rlb@hoekstra-uitgeverij.nl> wrote in message news:4180f756.197032434@news.individual.net... to news:comp.lang.c > ben19777@hotmail.com (Ben) wrote: > > 2) Structure casted into an...
13
by: Christopher Benson-Manica | last post by:
The thread where casting is being discussed motivated me to try this. Let's say you wanted to populate a BankRecord structure (as I defined below) with 17-character record numbers, but with the...
20
by: j0mbolar | last post by:
I was reading page 720 of unix network programming, volume one, second edition. In this udp_write function he does the following: void udp_write(char *buf, <everything else omitted) struct...
12
by: T Koster | last post by:
Hi lads, In implementing a hash table, I offer the option of storing arbitrarily-typed objects using a pointer-to-void. My hash function is as follows: unsigned int hashfn(void * key,...
19
by: Ramesh Tharma | last post by:
Hi, Is any one knows what's wrong with the following code, I was told that it will compile and run but it will crash for some values. Assume that variables are initilized. char* c; long*...
17
by: goldfita | last post by:
I saw some code that appeared to do something similar to this struct foo { char offset; int d; }; struct foo { int a; int b;
36
by: phil-news-nospam | last post by:
Here is a simpler (no drop shadows) example of the padding bug I see: http://phil.ipal.org/usenet/ciwas/2006-05-08/buttons-1.html So far I find nothing in the CSS2 document that says I should...
33
by: Mark P | last post by:
A colleague asked me something along the lines of the following today. For some type X he has: X* px = new X; Then he wants to convert px to a char* (I'm guessing for the purpose of...
7
by: William S Fulton | last post by:
I'm looking for the name of the following casting style in order to do some reading around on it and why it is sometimes used. unsigned long long ull = 0; void * ptr = 0; ull = *(unsigned...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.