我正在使用T-SQL和遊標來列出emp
數據庫。轉換varchar時轉換失敗。使用t-sql中的遊標工作
這裏是我的代碼:
DECLARE cursors CURSOR FOR
SELECT
emp.Ename, emp.Sal
FROM Emp
WHERE Sal > 200
DECLARE @surname VARCHAR(50), @salary INT
PRINT 'Employees earning more than 200:'
OPEN cursors
FETCH NEXT FROM cursors INTO @surname, @salary
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT @surname + ' ' + @salary
FETCH NEXT FROM cursors INTO @surname, @salary
END
CLOSE cursors
DEALLOCATE cursors
的問題是,當我嘗試執行我得到這個消息的代碼:
Employees earning more than 200: Msg 245, Level 16, State 1, Line 8
Conversion failed when converting the varchar value 'SMITH ' to data type int.
難道我做錯了什麼?如何解決它?
謝謝!有效! :) – Ganjira
@Ganjira歡迎您! :) –