如何修复SQL数据类型整数中的4位数 [英] How to fix 4 digits in SQL datatype integer

查看:106
本文介绍了如何修复SQL数据类型整数中的4位数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有一个Sql表,其中一列是串口没有数据类型是整数,

i尝试插入0001进入我的列序列号但它只是插入1但我想插入0001。



如何做到这一点可以任意一个帮我解决这个问题。





在此先感谢....

Hi,

I have a Sql Table in that one of the column is serial no datatype is integer,
i try to insert "0001" into my column serial no but it''s inserted as "1" only but i want to insert "0001".

How to do this can any one help me to resolve this issue.


Thanks in Advance....

推荐答案

对不起,你不知道自己在做什么。数字是一个数字。渲染方式是渲染细节。 1 IS 0001.唯一的区别在于它是如何显示的。因此,您的表示层需要格式化数字,它存储在数据库中的方式不会改变,也不能改变。
I''m sorry, but you have no idea what you''re doing. A number is a number. The way it''s rendered, is a rendering detail. 1 IS 0001. The only difference is how it''s shown. AS such, your presentation layer needs to format the number, the way it''s stored in the DB does not change, nor can it.


它将不考虑前导零在int或数列中保存记录。



这就是为什么如果你传递 0001 它保存为 1



代表带前导零的数字,



it will not consider leading zeros while save record inside int or numeric columns.

that''s why if you are passing 0001 it is saving as 1

for represent numeric with leading zeros,

select replicate('0', 4 - len(intColNm)) + convert(varchar,intColNm) from tblnm 





描述......

复制(复制字符串多少次你想要复制吗?



快乐编码!

:)



description...
replicate ( replicatetion string , howmany times you want to replicate? )

Happy Coding!
:)

这篇关于如何修复SQL数据类型整数中的4位数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆