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

  • Home
  • SEARCH
  • 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 someone please tell me which objects types can be tested using Regular Expressions
Somebody please tell me it is possible to recover Visual Studio source after VS
Can you please tell me how much is (-2) % 5 ? According to
Can anyone please tell me if Certifying Authorities (CAs) are allowed to make modifications
Could somebody please tell me what is Memory Page Out Rate. I have seen
I've recently written this with help from SO. Now could someone please tell me
Please don't answer the obvious, but what are the limit signs that tell us
Please tell me what's the different between Class1 and Class2 or the different between
Can someone please tell me how to find out the pathname of the KornShell
Please suggest some good resources to start writing Java Web services.

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.