Congratulations to all monthly winners of May 2013 !!! They have won INR 2900 cash and INR 27497 worth prize.
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 16825 |  Welcome, Guest!   Register  Login
 Home > Code Snippets > SQL Server > Reterieving the result of dynamic query in a variable. ...
Puneet20884

Reterieving the result of dynamic query in a variable.

 Code Snippet posted by: Puneet20884 | Posted on: 5/18/2010 | Category: SQL Server Codes | Views: 829 | Status: [Member] | Alert Moderator   
Ads

For this there are few tricks or the functionalities given by SQL.

1) Using a OUTPUT variable inside the dynamic query that sends the result of the dynamic query
2) Executing the query with sp_executesql function
3) Use of nVarchar type for cerating the dynamic query

The simple code goes as :

DECLARE @ValOut bigint


EXEC sp_executesql
N'SELECT TOP 1 @outPutValue = memberid FROM as_tblmembers order by 1 desc'
,N'@outPutValue bigint OUTPUT'
,@ValOut OUTPUT

SELECT @ValOut


Best Regards,
Puneet Sharma - Infosys
Pune, India
Found interesting? Add this to:


>> Write Response - Respond to this post and get points

More codes snippets

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 6/18/2013 2:11:13 AM