Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我将在持久列中使用什么公式,以便可以将下面的两列添加在一起,第一列必须填充为 5 个字符:
我去了format(ID,"00000") & RefNum,但它不起作用,请问有什么想法吗?
format(ID,"00000") & RefNum
你可以使用这样的东西:
ALTER TABLE dbo.YourTable ADD FormattedColumn AS RIGHT('00000' + CAST(ID AS VARCHAR(5)), 5) + RefNum PERSISTED
基本上,将 转换ID为 a VARCHAR(5),在它前面加上00000,然后抓住最右边的五个字符。
ID
VARCHAR(5)
00000
SELECT RIGHT('00000' + CAST(ID AS VARCHAR(5)), 5) + RefNum