.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal

Home >> Code Snippets >> SQL Query >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Sp_executeSql in Sql Server

Posted By:Deco       Posted Date: September 20, 2010    Points: 10    Category: SQL Query    URL: http://www.dotnetspark.com  

This code snippet will explain you how to use sp_executesql


SP_ExecuteSql provides greater compatibility with complex queries than the Exec

 Command. In some situation Exec command may fail but the SP_ExecuteSql will

get executed without any error.

Syntax :


EXEC SP_ExecuteSql 'T-Sql Query',

Parameters definition, Parameter, Parameter...

Example :


EXEC SP_ExecuteSql 

'SELECT FirstName, LastName 

 FROM [dbo].[UserDetails]

 WHERE UserID = @UserID', '@UserID INT', 

                  @UserID = 8282;


Result :

FirstName    LastName


Alwyn           Duraisingh


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend