本文介绍了如何使用行号()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
select 'D05503'+ROW_NUMBER() OVER(ORDER BY C_CODE),* from Tbl_Doc_Stock_Chem_Add_Mst where N_Type=1 and C_Code like 'sa%'
执行此查询时收到错误
如下所示:
While executing this query am getting error
like below:
Msg 8114, Level 16, State 5, Line 1
Error converting data type varchar to bigint.
数字应该是这样的:
Numbers should come like this:
D05503
D05504
D05505
D05506
D05507
D05508
推荐答案
SELECT 'D' + RIGHT('00000' + CONVERT(VARCHAR, 5503 + ROW_NUMBER() OVER (ORDER BY C_CODE)), 5), *
FROM bl_Doc_Stock_Chem_Add_Mst
WHERE N_Type=1 AND C_Code LIKE 'sa%'
WITH CTE AS (
SELECT ROW_NUMBER() OVER(ORDER BY C_CODE) rn
FROM Tbl_Doc_Stock_Chem_Add_Mst
WHERE N_Type=1
AND C_Code LIKE 'sa%'
)
SELECT 'D05503' + cast(rn as varchar) Somenumber
FROM CTE
这篇关于如何使用行号()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!