I am trying to modify the views in my database based on the input parameters. This procedure is to be executed using entity framework. The Error : Msg 214, Level 16, State 2, Procedure sp_executesql, Line 1 Procedure expects parameter '@statement' of type 'ntext/nchar/nvarchar'.
Code for Creating stored procedure using Dynamic SQL
Alter Procedure usp_Procedure_No
(
@value VARCHAR(255),
@constraint VARCHAR(255) = NULL
)
AS
BEGIN
EXEC sp_executesql @value, @constraint, N'
If @constraint = ''Gender''
BEGIN
alter View DupView
as
Select * from Personalities where Gender != @value
END
If @constraint = ''Place''
BEGIN
alter View DupView
as
Select * from Personalities where Place != @value
END
If @constraint = ''MaritalStatus''
BEGIN
alter View DupView
as
Select * from Personalities where MaritalStatus != @value
END
If @constraint = ''Age''
BEGIN
alter View DupView
as
Select * from Personalities where PersonalityAge != @value
END
If @constraint = ''Nationality''
BEGIN
alter View DupView
as
Select * from Personalities where Nationality != @value
END
If @constraint = NULL
BEGIN
alter View DupView
as
Select * from Personalities where Characterstics1 != @value OR Characterstics2!= @value OR Characterstics3 != @value
END
'
END
WHEREclause. You are doing much more than that. But why? If you are using entity framework just do it in your application code usingFind!