If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Migrate DIGITS() from DB2 to SQL Server

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-03-10, 05:46
nareshch nareshch is offline
Registered User
 
Join Date: Feb 2010
Posts: 2
Migrate DIGITS() from DB2 to SQL Server

Hi,

I am working on a migration from DB2 to SQL, i found one of my UDFs using the DIGITS() function. Can anybody suggest me what is the alternative in SQL.

Thank you...
Reply With Quote
  #2 (permalink)  
Old 02-03-10, 07:21
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Try CONVERT() or CAST()
Reply With Quote
  #3 (permalink)  
Old 02-03-10, 07:29
nareshch nareshch is offline
Registered User
 
Join Date: Feb 2010
Posts: 2
Thanks...any examples? and what would be the target data type when we do the conversion?
Reply With Quote
  #4 (permalink)  
Old 02-03-10, 08:21
Stealth_DBA Stealth_DBA is offline
Registered User
 
Join Date: May 2009
Posts: 472
DIGITS returns a character string representation of a number with leading zeros. The length of the character string depends on the data type of the number.

Small Integer returns a CHAR 5
Large Integer returns a CHAR 10
Big Integer returns a CHAR 19
Decimal returns a CHAR x where X is the Precision of the Decimal.

There isn't an exact equivalent in SQL. The closest single function is STR whose format is STR(value, length).

If you have a Smallint value of 29 you would use STR(29,5).

This will return a right justified number WITHOUT leading zeros.
Code:
DIGITS: 00029
STR:       29
If you can not work without leading zeros, you will need to do more work to add them.
Reply With Quote
  #5 (permalink)  
Old 02-03-10, 08:27
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Quote:
Originally Posted by nareshch View Post
Thanks...any examples? and what would be the target data type when we do the conversion?
So, you are planning to complete migration without ever opening the manual, aren't you? Good luck with that.
Reply With Quote
Reply

Tags
digits() from db2 to sql

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On