This is the error that may occur in the stored procedure.
Like what
Use [School]
go
alter Procedure [dbo].[ S_get_student]
(
@sex int --gender sex:1 (male) 2 (female)
)
as
begin
declare @sql varchar (max)-- Can contain many many characters
set @sql = ' SELECT * FROM dbo. Class where sex ' + @sex
exec (@sql)
end
--[s_get_student] 1
This situation prompts
Message 245, Level 16, State 1, Process s_get_student, line 8th
In the varchar value ' SELECT * FROM dbo. Class where sex ' conversion to data type int failed.
This is because your @sql is varchar value, and your @sex is shaping data
So you're going to convert @sex to the data type, and replace it with varchar.
Set @sql = ' SELECT * FROM dbo. Class where sex= ' +convert (varchar, @sex)
And, of course, it doesn't rule out anything else. You make the type of the concatenation statement the same for your variable convert (varchar,@x) because you can't add a date or an integer to a string
Click to open the link