列数据类型为NVARCHAR(MAX)
. 我怎样才能将其转换为Integer
?
CREATE TABLE UsrMast(Usr_Id int,
Usr_Pswd varchar(30),
Usr_Priv varchar(100))
CREATE TABLE T117_MenuMst(MenuID int,
Text varchar(50),
Description varchar(200),
ParentID int,
NavigateUrl varchar(100))
存储过程
CREATE PROCEDURE USP_MENUITEM (@UserID [varchar](50))
BEGIN
CREATE TABLE #TMP(MenuID INT, Text VARCHAR(50), Description VARCHAR(50), ParentID INT, NavigateUrl VARCHAR(100))
DECLARE @VAL NVARCHAR(MAX), @Pos INT, @len INT
--SET @VAL=(SELECT REPLACE(REPLACE(CONVERT(VARCHAR(30), SUM(CAST(PrivilegeID AS NUMERIC(30, 0)))), '2', '1'), '3', '1') FROM tblGroupPrivMst WHERE GroupCode in (SELECT GroupCode FROM tblUserGrpMap WHERE UserID=@UserID))
SET @VAL=(SELECT REPLACE(REPLACE(CONVERT(VARCHAR(70), SUM(CAST(Usr_Priv AS NUMERIC(38, 0)))), '2', '1'), '3', '1') FROM T112_UsrMast WHERE Usr_Id=@UserID)
SET @Pos=1
SET @len=LEN(@VAL)
WHILE(@len!=0)
BEGIN
DECLARE @Value CHAR(1)
SET @Value=SUBSTRING(@VAL, @Pos, 1)
IF @Value=1
BEGIN
PRINT @Value
INSERT INTO #TMP SELECT * FROM T117_MenuMst WHERE MenuID=@Pos
END
SET @Pos=@Pos+1
SET @len=@len-1
END
--For first Node (Inserting The Parent Node)
INSERT INTO #TMP SELECT * FROM T117_MenuMst WHERE MenuID IN(SELECT DISTINCT ParentID FROM #TMP WHERE ParentID NOT IN(SELECT MenuID FROM #TMP))
--For second Node (Inserting The Parent Node)
INSERT INTO #TMP SELECT * FROM T117_MenuMst WHERE MenuID IN(SELECT DISTINCT ParentID FROM #TMP WHERE ParentID NOT IN(SELECT MenuID FROM #TMP))
--For third Node (Inserting The Parent Node)
INSERT INTO #TMP SELECT * FROM T117_MenuMst WHERE MenuID IN(SELECT DISTINCT ParentID FROM #TMP WHERE ParentID NOT IN(SELECT MenuID FROM #TMP))
SELECT * FROM #TMP ORDER BY MenuID ASC
DROP TABLE #TMP
END
但我得到:
将 nvarchar 转换为数字数据类型时出现算术溢出错误。
UsrMast
表中的Usr_Priv
值为
10101111111111111111111111111111111111111111111111
请帮我。