在sql中插入一个从一位到三位的整数 [英] Inserting a integer in sql from one digit to three digit
本文介绍了在sql中插入一个从一位到三位的整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道一件事。我在表中有一个名为nos的列。现在我需要在tat列中插入1到999的s。如果我插入1它应该保存为001,如果我插入34它应保存为034.我想声明这个,而只指定列s。我不想运行单独的更新语句。有什么办法吗?
解决方案
你不能用整数或任何数字类型做这个 - 你需要使用varchar或等效的数据库。
尝试像
SELECT TOP 10 RIGHT (' 0000000'
+ CAST(TrnID AS VARCHAR ( 7 )), 7 )PaddedContactID
FROM tbl_Trn_Payments
GO
Hi i'd like to know one thing. i have a column called nos in a table. now i need to insert no s from 1 to 999 in tat column. if i insert 1 it should save as 001 and if i insert 34 it should save as 034. i want to declare this while specify the column s only. i dont want to run a seperate update statement.is there any way for this?
解决方案
You cannot do this with integer or any numeric type - you need to use varchar or the database equivalent.
Try like
SELECT TOP 10 RIGHT('0000000' + CAST(TrnID AS VARCHAR(7)), 7) PaddedContactID FROM tbl_Trn_Payments GO
这篇关于在sql中插入一个从一位到三位的整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文