If the SQL Condition Statement whereidin (@ parameter) is executed improperly, the following problems may occur:
If the SQL condition statement where id in (@ parameter) is executed improperly, the following problems may occur:
If the SQL condition statement where id in (@ parameter) is executed improperly, the following problems may occur:
See the following stored procedure:
Alter proc web_gettwgoldgameservergoldsell
@ ID int
As
Declare @ twgoldsellID nvarchar (1000)
Select @ twgoldsellID = twgoldsellID from twgoldgameserver where ID = @ ID
Set @ twgoldsellID = replace (@ twgoldsellID, '| ',',')
Set @ twgoldsellID = left (@ twgoldsellID, len (@ twgoldsellID)-1)
Select * from twgoldsell where ID in (@ twgoldsellID)
It seems that there is no problem, but an error is reported during execution:
Message 245, level 16, state 1, 1st rows
An error occurred while converting the varchar value '2017, 813,116, 1227,1232 'to the Data Type int.
In fact, when this statement is executed,
Select * from twgoldsell where ID in (@ twgoldsellID)
The executed statement is: select * from twgoldsell where ID in ('2017 813,116, 1219, 1227,1232 ')
An error occurs because @ twgoldsellID is a string and is passed as a parameter.
Solution:
Select * from twgoldsell where ID in (@ twgoldsellID)
Changed:
Exec ('select * from twgoldsell where ID in ('+ @ twgoldsellID + ')')
Remember: you must add exec to execute the function. Otherwise, the following error will be reported:
Message 245, level 16, status 1, process web_gettwgoldgameservergoldsell, row 8th
Failed to convert varchar value '+ @ twgoldsellID +' to data type int.
,