sm_Value
是一個TEXT
列,我需要將其轉換爲INT
。在SQL中將文本轉換爲INT
作爲一個事實,即只有兩個人會亂用這個表中,列將是數值(幽默我)
我收到此錯誤信息:
消息206,級別16,狀態2,過程User_Password_Date_Interval_Check,10號線
操作數類型衝突:文本與詮釋
不相容我曾嘗試:
SELECT CONVERT(INT, sm_Value))
FROM Setting_Misc
但我仍然得到錯誤。
IF EXISTS (SELECT * FROM sysobjects
WHERE type = 'P' AND name = 'User_Password_Date_Interval_Check')
BEGIN
PRINT 'Dropping Procedure User_Password_Date_Interval_Check'
DROP Procedure User_Password_Date_Interval_Check
END
GO
PRINT 'Creating Procedure User_Password_Date_Interval_Check'
GO
CREATE Procedure User_Password_Date_Interval_Check
@ua_pk uniqueidentifier
AS
DECLARE @PasswordExpireDays INT
SELECT
CONVERT(INT, CONVERT(VARCHAR(MAX), sm_Value))
FROM Setting_Misc
SELECT
@PasswordExpireDays = COALESCE(sm_Value,0)
FROM
Setting_Misc AS sm
INNER JOIN
Syndicates As syn ON sm.syn_fk = syn.syn_pk
INNER JOIN
Company As c ON c.syn_fk = syn.syn_pk
INNER JOIN
User_Accounts As ua ON ua.c_fk = c.c_pk
WHERE
sm.sm_Setting = 'PasswordExpireDays'
GO
GRANT EXEC ON User_Password_Date_Interval_Check TO WEB
你爲什麼先把它轉換成varchar(max)? – scsimon
[將數字轉換成文本數據類型轉換爲int](http://stackoverflow.com/questions/15346002/convert-number-stored-as-text-data-type-to-int) – dfundako
'@PasswordExpireDays '似乎是你的錯誤是如此只是將它轉換爲'@PasswordExpireDays = COALESCE(CONVERT(INT,CONVERT(varchar(max),sm_Value)),0)' – scsimon