如何获取BIGINT序列值并将其放入VARCHAR?

时间:2014-07-10 04:59:51

标签: sql-server

我创建了这个序列:

CREATE SEQUENCE [dbo].[TestIdMaster]
    AS BIGINT
    START WITH 1
    INCREMENT BY 1
    NO CACHE;

我知道我可以像这样得到价值:

 DECLARE @TestId AS INT
    = NEXT VALUE FOR DBO.TestIdMaster

但是我想在varchar中使用这个值,并想为它添加一个连字符。那么如何获取值并将其转换为varchar?

1 个答案:

答案 0 :(得分:0)

像这样:

DECLARE @v VARCHAR(50) 
DECLARE @TestId AS INT = NEXT VALUE FOR DBO.TestIdMaster
SET @v = CONVERT(VARCHAR(50),@TestId) + '-'