varchar数据类型的增量 [英] Increment in varchar data type
本文介绍了varchar数据类型的增量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好
我建了表名sale_invoice。我希望在我的ID字段中增加一个。
喜欢这个...
LE001001
LE001002
LE001003
LE001004
。
。
。
。
所以..
任何人都可以帮助我
先谢谢
解决方案
阅读本文: http://www.sqlteam.com/article/custom-auto-generated-sequences-with-sql-server [ ^ ]
你可能想要尝试这个也
创建 表 #temp
(
Id int identity ( 1001 , 1 ),
user_code as ' LE' + REPLICATE(' 0',6-Len(Id))+转换( Varchar ( 10 ),Id)
)
INSERT INTO #temp DEFAULT VALUES
INSERT INTO #temp DEFAULT VALUES
INSERT INTO #temp DEFAULT VALUES
简单,只需创建如下表格设计:
<前lang =sq l> 创建 表表1
(
Id int identity ( 1 , 1 ),
user_code as case len(Id)当 1 然后 ' LE00100' + convert( varchar ,ID)
当 2 然后 ' LE0010' + convert( varchar ,ID)
< span class =code-keyword>当 2 然后 '跨度>LE001' + convert( varchar ,ID)
else ' LE' + convert( varchar ,ID)
end
)
测试:
INSERT INTO 表1 DEFAULT VALUES 跨度>;
INSERT INTO 表1 DEFAULT VALUES
INSERT INTO 表1 DEFAULT VALUES
INSERT < span class =code-keyword> INTO 表1 DEFAULT VALUES
< span class =code-keyword> INSERT INTO 表1 DEFAULT VALUES 跨度>;
选择 *来自Table1
Hi All
I have build table name sale_invoice. I want one increment in my ID field.
Like This...
LE001001
LE001002
LE001003
LE001004
.
.
.
.
So on..
Can any one help me please
Thanks in Advance
解决方案
Read this : http://www.sqlteam.com/article/custom-auto-generated-sequences-with-sql-server[^]
You may want to try this also
Create table #temp ( Id int identity(1001,1), user_code as 'LE'+REPLICATE('0',6-Len(Id))+Convert(Varchar(10),Id) ) INSERT INTO #temp DEFAULT VALUES INSERT INTO #temp DEFAULT VALUES INSERT INTO #temp DEFAULT VALUES
Simple ,Just Create a Table Design like below:
create table Table1 ( Id int identity(1,1), user_code as case len(Id) when 1 then 'LE00100'+convert(varchar,ID) when 2 then 'LE0010'+convert(varchar,ID) when 2 then 'LE001'+convert(varchar,ID) else 'LE'+convert(varchar,ID) end ) Test: INSERT INTO Table1 DEFAULT VALUES; INSERT INTO Table1 DEFAULT VALUES INSERT INTO Table1 DEFAULT VALUES INSERT INTO Table1 DEFAULT VALUES INSERT INTO Table1 DEFAULT VALUES; select *From Table1
这篇关于varchar数据类型的增量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文