In MySQL, we can generate the prepared statement using PreparedStatement.
I want to achieve the same functionality in SQL script. How to create the prepared statement and how to execute it? Please provide an example for that.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I would suggest using
sp_executesqloverexecfor most dynamic SQL.sp_executesqlis similar to MySQL’sEXECUTE...USINGin that it can take parameters rather than only concatenated strings, thus giving you a good defense against SQL injection.sp_executesqlalso allows SQL Server to reuse the query plan for more efficient querying. Here’s an example:Some more info and examples can be found here.