简体   繁体   中英

How do I replicate a To_Char function from Oracle in MSSQL?

Currently I have a working To_Char in Oracle:

To_Char($Num,'FM' || RPAD(RPAD(LPAD(LPAD('.',least($intmaxlength,$intminlength)+1,'0'),$intmaxlength+‌​1,'9'),$intmaxlength+1+$decminlength,'0'),$intmaxlength+1+$decmaxlength,'9'))

My goal is to convert a number to a string, fitting into four parameters for integers and decimals.

I would like to add minimum and maximum precision. For example, the integers to the left of the decimal point in 1234567.89 should have a minimum of 1 but a maximum of five (so the extra integers would be trimmed). In addition, I'd like to do the same for scale - the decimals to the right, by setting a minimum of two decimal places and a maximum of four. These numbers are just examples, the numbers will be updated dynamically.

I have minimal experience in MSSQL, but from what I can see some equivalent functions like Least are missing in it versus Oracle.

Here are string functions for MSQL

https://msdn.microsoft.com/en-us/library/ms181984.aspx

for least i dont think there is any equivalent.

But i found this getting-the-minimum-of-two-values-in-sql

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM