列數據類型爲NVARCHAR(MAX)
。我如何將它轉換爲Integer
?將NVARCHAR轉換爲INT
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 [email protected]))
SET @VAL=(SELECT REPLACE(REPLACE(CONVERT(VARCHAR(70), SUM(CAST(Usr_Priv AS NUMERIC(38, 0)))), '2', '1'), '3', '1') FROM T112_UsrMast WHERE [email protected])
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 [email protected]
END
SET @[email protected]+1
SET @[email protected]
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
請幫助我。
***什麼數據庫系統***和這是哪個版本? –
在大多數數據庫系統中,「INT」的**最大**值是2'147'483'648(剛超過20億)。你的字符串對於'INT'來說太**了!這就是**完全**錯誤是什麼意思... –
我使用SQLSERVER 2008R2,N我的錯誤正是「算術溢出錯誤將nvarchar轉換爲數據類型數字。」 – Bannu