Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 759331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:34:59+00:00 2026-05-14T15:34:59+00:00

Please tell me what is difference ==> if i write query directly in storedprocedure

  • 0

Please tell me what is difference
==> if i write query directly in storedprocedure
==> and write query in string variable and than run it in exec in stored procedure.

i am using ms sql server 2005

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T15:34:59+00:00Added an answer on May 14, 2026 at 3:34 pm

    With some exceptions EXEC('sql stmnt') is what you use when you have no other choice.

    It allows you to dynamically build a statement and execute it, which is often the only way of achieving something when object names are variable and not known in advance.

    Read this article on dynamic SQL which explains scenarios when/why dynamic SQL is useful & goes into detail about EXEC().

    As for the differences between running an SQL statement in a stored procedure and running it in the procedure as EXEC(@SQL_STRING):

    • None of the objects referenced in @SQL_STRING will be checked
    • None of the T-SQL code will be verified for syntax and type checking
    • Stuff in @SQL_STRING is within its own scope relative to the SP
    • You risk being careless and poorly forming @SQL_STRING which can lead to security problems.
    • The query plan for @SQL_STRING will be cached but only reused if a subsequent EXEC(@SQL_STRING) matches it exactly, with an SP a single query plan can be reused if all that changes are parameters.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Could you please tell me the difference between using asp.net validator controls vs JQuery
Can any one please tell me the difference between target and currenttarget in flex?
Can somebody please tell, what's the difference between the following two statements: TimeZone.getTimeZone(America/New_York) and
could anyone please tell me, where in Javascript the difference between MyClass.prototype = new
Please tell me the difference between stack and heap with respect to below code
can somebody please tell me the difference between the following two code snippets: //Code
Please tell me what difference between pthread versions: VC2, VCE2 and VSE2? How to
Is it possible to run more than one virtual machines on my PC using
Can someone please tell me the difference exactly between these 2 RegEx's? '/[^a-zA-Z0-9\s]/' and
can somebody please tell me the difference if i do in my ActionResult in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.