Advertisement

06.15.2006 at 09:00PM PDT, ID: 21888499
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.6

Left Pad a String

Asked by RickJ in MS SQL Server

Tags: , ,

Hello,
I have a string that I need to left pad with zeros.
The string actually represents a number value. The string is length 30.
I need a query to return the string left padded to the length of the largest string. example as below.

129736
13085
1308

these would be rreturned as

129736
013085
001308

Now.. This isnt for MS SQL but for Advantage Database Server. I know this is the MS SQL T/A but I thought it would be the best place to get an answer.
There are no padding functions available. The following is a list of available functions.

CONVERT( expr, data-type )      Returns the value of expr converted to data-type. The data-type parameter can be SQL_BINARY, SQL_VARBINARY, SQL_BIT (logical), SQL_VARCHAR, SQL_CHAR, SQL_DATE, SQL_DOUBLE, SQL_INTEGER, SQL_NUMERIC, SQL_TIME, or SQL_TIMESTAMP.
ASCII( str )      Returns integer ASCII value for single character at start of str.
BIT_LENGTH( str )      Returns length of str in bits (assumes 8-bit characters).
CHAR( int )      Returns a character value from ASCII integer.
CHAR_LENGTH( str )      Returns the length of string in characters.
CHARACTER_LENGTH( str )      Returns the length of string in characters.
CONCAT( str1, str2 )      Returns a string that is the result of concatenating str2 to str1.
INSERT( str1, start, len, str2 )      Returns a string where str2 into str1 at position start for at most len characters, replacing len characters.
LCASE( str )      Returns string with all uppercase characters converted to lowercase.
LEFT( str, count )      Return the left part of string str up to count characters.
LENGTH( str )      Returns the number of characters in str, excluding trailing blanks.
LOCATE( str1, str2[, start] )      Return integer location (1-based) of str1 in str2, with optional start starting point.If str1 is not found in str2, 0 is returned.
LTRIM( str )      Returns string with leading spaces from left side of string.
OCTET_LENGTH( str )      Returns length of string in octets (i.e., bytes).
POSITION( str1 IN str2 )      Returns the position of str1 in str2.
REPEAT( str, cnt )      Returns a string consisting of str repeated up to cnt times.
REPLACE( str1, str2, str3 )      Replace all occurrences of str2 in str1 with str3.
RIGHT( str, count )      Returns a string of count characters of right part of str.
RTRIM( str )      Returns a string with trailing spaces removed from right side of string.
SPACE( count )      Returns a string of space repeated up to count times.
SUBSTRING( str, pos, len )      Returns a portion of str starting at pos, up to length len.
UCASE( str )      Returns a string with all lowercase characters converted to uppercase.
UPPER (str)      Returns a string with all lowercase characters converted to uppercase.
ABS( num )      Returns the absolute value of a numeric.
ACOS( float )      Returns the arccosine of float as an angle, expressed in radians.
ASIN( float )      Returns the arcsine of float as an angle, expressed in radians.
ATAN( float )      Returns the arctangent of float as an angle, expressed in radians.
ATAN2( float1, float2 )      Returns the arctangent of the x and y coordinates, specified by float1 and float2, as an angle, expressed in radians.
CEILING( num )      Returns the smallest integer greater than or equal to num. The return value is of the same data type as the input parameter.
COS( float )      Returns the cosine of float, where float is an angle expressed in radians.
COT( float )      Returns the cotangent of float, where float is an angle expressed in radians.
DEGREES( num )      Returns the number of degrees converted from radians.
EXP( float )      Returns the exponential value of float.
FLOOR( num )      Returns the largest integer less than or equal to num. The return value is of the same data type as the input parameter.
LOG( float )      Returns the natural logarithm of float.
LOG10( float )      Returns the base 10 logarithm of float.
MOD( int1, int2 )      Returns the modulus (remainder) of int1 divided by int2.
PI( )      Returns the value of pi as a floating point value constant.
POWER( num, int )      Returns the value of num raised to the power of int.
RADIANS( num )      Returns the number of radians converted from degrees.
RAND( [int] )      Returns a random floating point value using int as an optional seed value. If zero is specified as the seed value, the current time in milliseconds is used as the seed.
ROUND( num, int )      Returns num rounded to int places to the right of the decimal point. If int is negative, num is rounded to ABS(int) places to the left of the decimal point.
SIGN( num )      If num is less than zero, –1 is returned. If num equals zero, 0 is returned. If num is greater than zero, 1 is returned.
SIN( float )      Returns the sine of the float expression, where float is an angle expressed in radians.
SQRT( float )      Returns the square root of float.
TAN( float )      Returns the tangent of float, where float is an angle expressed in radians.
TRUNCATE( num, int )      Returns num truncated to int places to the right of the decimal point. If int is negative, num is truncated to ABS(int) places to the left of the decimal point.

This probably easy, but my head hurts.
Thanks for any help.Start Free Trial
[+][-]06.15.2006 at 09:20PM PDT, ID: 16917614

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 14-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]06.15.2006 at 09:33PM PDT, ID: 16917658

View this solution now by starting your 14-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: MS SQL Server
Tags: left, pad, sql
Sign Up Now!
Solution Provided By: Yurich
Participating Experts: 3
Solution Grade: A
 
 
[+][-]06.15.2006 at 09:36PM PDT, ID: 16917669

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 14-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]06.15.2006 at 09:51PM PDT, ID: 16917724

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.15.2006 at 11:30PM PDT, ID: 16918051

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20081112-EE-VQP-43