在sql中转换和子串一起

时间:2017-08-25 13:23:34

标签: sql-server sql-server-2008

需要帮助来纠正sql查询中的语法。

OPEN SYMMETRIC KEY symmetrickey_ccprocessing
DECRYPTION BY CERTIFICATE certificate_ccprocessing;
SET NOCOUNT ON;
select CONVERT(VARCHAR, DECRYPTBYKEY(c.CR_CARD_NBR)) AS CR_CARD_NBR
from dbo.credit C
CLOSE SYMMETRIC KEY symmetrickey_ccprocessing;

我需要列CR_CARD_NBR的前两个字符。 如何使用字符串并使用解密密钥进行转换。

提前致谢。

1 个答案:

答案 0 :(得分:0)

用左(xxx,2)包围它,就像这样;

OPEN SYMMETRIC KEY symmetrickey_ccprocessing
DECRYPTION BY CERTIFICATE certificate_ccprocessing;
SET NOCOUNT ON;
select LEFT(CONVERT(VARCHAR, DECRYPTBYKEY(c.CR_CARD_NBR)),2) AS CR_CARD_NBR
from dbo.credit C
CLOSE SYMMETRIC KEY symmetrickey_ccprocessing;