本文介绍了添加0前面的数字SQL Server 2k8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有来自tablename的列SL nvarchar(5)
SL SL
1/2 1/2
3 - > 03
23 23
5 05
选择
i have column SL nvarchar(5) from tablename
SL SL
1/2 1/2
3 --> 03
23 23
5 05
select
(replace(left(REPLACE(STR(sl,3),' ','0'),1),'0','')+
right(REPLACE(STR(sl,3),' ','0'),2)) as slmax
来自tablename
我尝试了什么:
但是没有用,我可以用SL(nvarchar)解决1/2。帮助我
from tablename
What I have tried:
but didn't work ,i can't solve 1/2 with SL(nvarchar). helps me
推荐答案
int x;
string result = int.TryParse(input, out x) ? x.ToString("D2") : input;
这是一个演示函数,而不是数据存储函数,应该这样处理。
仅仅因为它可以在SQL中完成并不意味着它应该!
This is a presentation function, not a data storage function, and should be handled as such.
Just because it could be done in SQL doesn't mean it should!
这篇关于添加0前面的数字SQL Server 2k8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!