SQL中的组合列



我有一个包含这些列的表:

  • 模块varchar
  • <
  • 周期日期/gh>
  • autoNum int
SELECT TOP 1000 [id]
,[module]
,FORMAT([cycle],'yyyyMM') as cycle
,RIGHT('000000'+CAST([autoNum] as varchar(5)),5) as autoNum

FROM [Inventory].[dbo].[tbl_invoiceGIN]
autoNum0000100001

重复表达式:

SELECT TOP 1000 [id]
,[module]
,FORMAT([cycle],'yyyyMM') as cycle
,RIGHT('000000'+CAST([autoNum] as varchar(5)),5) as autoNum
,FORMAT([cycle],'yyyyMM') + '-' +  RIGHT('000000'+CAST([autoNum] as varchar(5)),5) As DocNo    
FROM [Inventory].[dbo].[tbl_invoiceGIN]

或者使用嵌套SELECT语句:

SELECT TOP 1000 id, [module], cycle, autoNum, cycle+'-'+autoNum As DocNo
FROM (
SELECT [id]
,[module]
,FORMAT([cycle],'yyyyMM') as cycle
,RIGHT('000000'+CAST([autoNum] as varchar(5)),5) as autoNum  
FROM [Inventory].[dbo].[tbl_invoiceGIN]
) i

相关内容

  • 没有找到相关文章

最新更新