ALL stored procedure
USE [amozeshgah]
GO
/****** Object: StoredProcedure [dbo].[selectmanageregistercourse] ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[selectmanageregistercourse]
@iddore int,
@stateregister int,
@userid nvarchar(350)
AS
declare @str nvarchar(900)
BEGIN
SET @str= 'SELECT tblUserRegisterDore.id, tblUserRegisterDore.idcourse, tblUserRegisterDore.iddore, tblUserRegisterDore.userid, tblUserRegisterDore.coderegister, tblUserRegisterDore.fish, tblUserRegisterDore.date, tblUserRegisterDore.statefish, tblUserRegisterDore.stateregister, tbluser.name, tbldore.name AS namesubcourse, tblmozedore.name AS namecourse, tbluser.family FROM tblUserRegisterDore INNER JOIN tblmozedore ON tblUserRegisterDore.idcourse = tblmozedore.id INNER JOIN tbldore ON tblUserRegisterDore.iddore = tbldore.id AND tblmozedore.id = tbldore.idmozedore INNER JOIN tbluser ON tblUserRegisterDore.userid = tbluser.userid where iddore='+convert(nvarchar(100),@iddore)
if (@stateregister<>-1)
begin
set @str +=' and stateregister='+ convert(varchar(100),@stateregister)
end
if (@userid <>'-1')
begin
set @str +=' and tblUserRegisterDore.userid='+ @userid
end
EXEC sp_executesql @str
END
when run query vlaue @userid in where error ‘Invalid column name value @user id’
parameters that are passed
EXEC @return_value = [dbo].[selectmanageregistercourse]
@iddore = 3,
@stateregister = 1,
@userid = N'fdfsdf'
error
Msg 207, Level 16, State 1, Line 1
Invalid column name ‘fdfsdf’.
why?
There are many issues here and it seems the file you are showing is not the one you are using on the server.
Here is how to create SP and not use dynamic SQL — it will be much faster and easier to use:
Prior comment no longer applies if you use above
However, here is one issue. You have a
varcharand you are not using quotes around it in the dynamic sql you are creating.should be