-1

Good Morning DBA's, I need a function to pulls an int DocumentID column and returns the lowest thousand int. The limitation is our result must have 8 chars and the leading characters need to be 0's.

  • Example 1: 1234 (int contained in DocumentID column) Result: 00001000 (generated by function in result set)

  • Example 2: 1152534 Result: 01152000

Result Set...

DocumentID Function 

1234       00001000 
1152534    01152000
tshepang
  • 12,111
  • 21
  • 91
  • 136
Chase Cabrera
  • 83
  • 1
  • 1
  • 6

2 Answers2

0

Here is the basic structure. The exact commands may vary depending on the RDBMS.

right('00000000'||cast(DocumentID as varchar(8)),8)

Declan_K
  • 6,726
  • 2
  • 19
  • 30
0

this is for SQL Server (based on @Declan_K's answer)

SELECT RIGHT('0000' + CONVERT(VARCHAR(5), DocumentID  /1000) , 5)+ '000'
Luis LL
  • 2,912
  • 2
  • 19
  • 21