我创建了一个编号重复值的视图。代码是:
SELECT *,RANK() OVER(PARTITION BY Lookup ORDER BY n) AS rank
FROM dbo.PENTACIA_PO_QTY
查找也是表格中的一列。
当我想要CONCAT
重复值时,例如。 COL.NAME
具有排名数字,即
TEST1
TEST2
NAME1
它给了我:Error Converting data type nvarchar to bigint error.
为什么?
THE CONCAT CODE:
我试着在排名的同时做到这一点:
SELECT *,CardCode + RANK() OVER(PARTITION BY Lookup ORDER BY Lookup) AS rank
FROM dbo.PENTACIA_PO_QTY`
答案 0 :(得分:1)
RANK()
返回BIGINT
- 您无法使用operator +将其连接到* CHAR列
您可以将RANK()
结果转换或转换为* char,例如
SELECT *,
CardCode + CAST(RANK() OVER(PARTITION BY Lookup ORDER BY Lookup) AS VARCHAR(20))
AS CardPlusRank
FROM dbo.PENTACIA_PO_QTY;