How to pad with leading zeros an int or smallint in Sybase?
Submitted by: AdministratorBy example:
declare @Integer int
/* Good for positive numbers only. */
select @Integer = 1000
select "Positives Only" =
right( replicate("0", 12) + convert(varchar, @Integer), 12)
/* Good for positive and negative numbers. */
select @Integer = -1000
select "Both Signs" =
substring( "- +", (sign(@Integer) + 2), 1) +
right( replicate("0", 12) + convert(varchar, abs(@Integer)), 12)
select @Integer = 1000
select "Both Signs" =
substring( "- +", (sign(@Integer) + 2), 1) +
right( replicate("0", 12) + convert(varchar, abs(@Integer)), 12)
go
Produces the following results:
Positives Only
--------------
000000001000
Both Signs
-------------
-000000001000
Both Signs
-------------
+000000001000
Submitted by: Administrator
declare @Integer int
/* Good for positive numbers only. */
select @Integer = 1000
select "Positives Only" =
right( replicate("0", 12) + convert(varchar, @Integer), 12)
/* Good for positive and negative numbers. */
select @Integer = -1000
select "Both Signs" =
substring( "- +", (sign(@Integer) + 2), 1) +
right( replicate("0", 12) + convert(varchar, abs(@Integer)), 12)
select @Integer = 1000
select "Both Signs" =
substring( "- +", (sign(@Integer) + 2), 1) +
right( replicate("0", 12) + convert(varchar, abs(@Integer)), 12)
go
Produces the following results:
Positives Only
--------------
000000001000
Both Signs
-------------
-000000001000
Both Signs
-------------
+000000001000
Submitted by: Administrator
Read Online Sybase Job Interview Questions And Answers
Top Sybase Questions
☺ | What is a Coalesce? What is the equivalent of Oracle/Db2 Coalesce Function in Sybase? |
☺ | How to pad with leading zeros an int or smallint in Sybase? |
☺ | Explain about the features of Sybase IQ? |
☺ | How can I execute dynamic SQL with ASE in Sybase? |
☺ | Explain about Power Designer Data modeling software? |
Top Databases Programming Categories
☺ | RDBMS Interview Questions. |
☺ | SQL Interview Questions. |
☺ | SSRS Interview Questions. |
☺ | Database Administrator (DBA) Interview Questions. |
☺ | Sybase Interview Questions. |