The database designs fields as decimal, so each stored field has five valid numbers ~ Example: 50000.00000
In my previous task, we set two numbers and two conditions in four fields to 0 <x <= 100, all numbers have five valid decimals. The SQL statement is as follows:
Select Factorname, Rs. factorid,
Rs. rewardstandardid, Rs. ruletemplateid,
Case ABS (Conditionlowerbound) When 999999999 Then '' Else Convert ( Varchar , Conditionlowerbound) +
Case Convert ( Varchar , Conditionlowerboundcontain) When 0 Then ' < ' When 1 Then ' <= ' End
End + ' X ' + Case ABS (Conditionupperbound) When 999999999 Then '' Else +
Case Convert ( Varchar , Conditionupperboundcontain) When 0 Then ' < ' When 1 Then ' <= ' End +
Convert ( Varchar , Conditionupperbound) End As Expression, standardvalue
From Rewardstandard rs Left Join Rewardcomputingfactor RF On Rs. factorid = RF. factorid
Where 1 = 1
The output is as follows:
Obviously, the expression is ugly ~ Therefore, the current task should change it to a normal number:
I searched the internet and found that there were no prepared answers. Maybe the university thought it was very simple, or I couldn't express it clearly. For example, I do not know how to better express this title. Haha ~
Try the following methods: Select Right ( 1000 + 4555 , 3 )
Select Stuff ( Convert ( Varchar ,( 1000 + 4655 )), 1 , 1 , '' )
Select Replicate ( ' 0 ' , 3 - Len ( Convert ( Varchar , 5 ))) + Convert ( Varchar , 5 )
Select Right ( 1000 + Conditionupperbound, 10 ) From DBO. rewardstandard
Select * From Rewardstandard
Select To_char ( 12.1 , ' 99.00 ' ) From Rewardstandard
Declare @ Jj Decimal ( 5 , 2 )
Set @ Jj = 123.00
Select Convert ( Varchar ( 30 ), @ Jj )
Select Convert ( Varchar , Convert ( Float , Conditionupperbound )) From DBO. rewardstandard
I found that there is a good method to take the last few digits after formatting, for example, 5 format to 005, select right (1000 + 5, 3), huh, huh, isn't it very easy?
My problem has not been solved yet ~ Finally, I accidentally combined and found a solution. First, convert the number to float and then varchar, as shown below:Select Convert(Varchar,Convert(Float, Conditionupperbound ))FromDBO. rewardstandard
So, My SQL is like this ~ Select Factorname, Rs. factorid,
Rs. rewardstandardid, Rs. ruletemplateid, billingmonth, Rs. basetableid, Rs. factorid,
Case ABS (Conditionlowerbound) When 999999999 Then '' Else Convert ( Varchar , Convert ( Float , Conditionlowerbound )) +
Case Convert ( Varchar , Conditionlowerboundcontain) When 0 Then ' < ' When 1 Then ' <= ' End
End + ' X ' + Case ABS (Conditionupperbound) When 999999999 Then '' Else +
Case Convert ( Varchar , Convert ( Float , Conditionupperboundcontain )) When 0 Then ' < ' When 1 Then ' <= ' End +
Convert ( Varchar , Convert ( Float , Conditionupperbound )) End As Expression, Convert ( Varchar , Convert ( Float , Standardvalue ))
From Rewardstandard rs Left Join Rewardcomputingfactor RF On Rs. factorid = RF. factorid
Where 1 = 1