将记录提取到表的问题 [英] problem to fetch record to table
本文介绍了将记录提取到表的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
朋友们,我有一张桌子
喜欢
hi friends i have one table
like
id name
1 AAA
2 BBB
3 CCC
我想记录这个
and i want to record lik this
id
0001
0002
0003
感谢提前
Thanks to advance
推荐答案
您需要转换号码ID吗?
您可以这样做。
Do you need to convert number ID?
You can do this.
SELECT RIGHT('0000' + CONVERT(varchar, id), 4), name FROM table;
USE [cpqaAnswers]
GO
CREATE TABLE [cpqa].[tbl_RP_zeropadSolution005]
(
P_Id int,
amount varchar(50),
name nvarchar(10)
)
INSERT INTO [cpqa].[tbl_RP_zeropadSolution005]
VALUES(1, '9', 'Tintin'),
(2, '361','TakTak'),
(3, '542','Toucan'),
(4, '2010','Tallidego')
SELECT * FROM [cpqa].[tbl_RP_zeropadSolution005]
SELECT * FROM [cpqa].[tbl_RP_zeropadSolution005] ORDER BY [amount]
将前两个SELECT比较为:
Compare previous two SELECT to this:
SELECT [P_Id], LEFT(REPLICATE('0', 6), 6 - LEN([amount])) + [amount] AS [zeropadded_amount], [name] FROM [cpqa].[tbl_RP_zeropadSolution005]
SELECT [P_Id], LEFT(REPLICATE('0', 6), 6 - LEN([amount])) + [amount] AS [zeropadded_amount], [name] FROM [cpqa].[tbl_RP_zeropadSolution005] ORDER BY [zeropadded_amount] DESC
将上面的内容复制并粘贴到New Query中,点击F5查看。
Copy and paste the above into New Query and hit F5 to see.
这样的东西:
Something like this:
SELECT RIGHT('000'+ CONVERT(VARCHAR, Id), 6) AS Result FROM MyTable;
这篇关于将记录提取到表的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文