Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

LPAD (Oracle) convert to SQL equivalent

Status
Not open for further replies.

outofservice

Technical User
Feb 20, 2002
33
GB

Here is some Oracle PLsql that needs to be converted to its SQL Server equivalent.

Oracle SQL is:

SELECT lpad(n_num+600000, greatest(length(n_num+600000), length(n_num)),0) FROM numbr;

It takes the n_num column from the numbr table and increases the number by the set amount.

eg n_num
00123 + 8 = 00131
00123 + 60 = 00183
00123 + 600 = 00723
00123 + 6000 = 06123
00123 + 60000 = 60123
00123 + 600000 = 600123

But if the number is prefixed by 0's (zero's) it puts them back on, or if the end number is the same length as the original numbers length, with any prefix, it does not put the prefix on. The same for if the number goes above the original length.

Thanks for your help. Lauryn Bradley
SQL Server DBA
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top