Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2005 > SQL Server 2005
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
SQL Server 2005 General discussion of SQL Server *2005* version only.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2005 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 5th, 2008, 03:43 AM
Registered User
 
Join Date: Apr 2008
Location: mumbai, maharashtra, India.
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to mahen_pali Send a message via Yahoo to mahen_pali
Default get the execute query result in variable

hello all of you

i want to get the execute query result in variable
Here is code

declare @Trans varchar(50)
set @Trans = 'Trans'
declare @val int
set @val = (execute('select count(*) from '+@Trans))

How can i solve that please help me soon

mahendra singh
Reply With Quote
  #2 (permalink)  
Old April 7th, 2008, 03:41 AM
Authorized User
 
Join Date: Jun 2003
Location: Colombo 04, WP, Sri Lanka.
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Preethi Send a message via Yahoo to Preethi
Default

To Get the value back to a variable you should use sp_ExecuteSQL
Here is an example of what I tried against AdventureWorks

DECLARE @SQL nvarchar(2000), @Rows int
SET @SQL =N'SELECT @RowCount =COUNT(*) FROM '+ +'Sales.SalesOrderHeader'
EXEC sp_ExecuteSQL @SQL, N'@RowCount int OUTPUT',@RowCount=@Rows OUTPUT
SELECT @Rows

I purposefully used @RowCount and @Rows to differentiate them. Hope this helps


G.R.Preethiviraj Kulasingham
Reply With Quote
  #3 (permalink)  
Old April 7th, 2008, 04:04 AM
Registered User
 
Join Date: Apr 2008
Location: mumbai, maharashtra, India.
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to mahen_pali Send a message via Yahoo to mahen_pali
Default

My hearty thanks to Preethi

My problem have solved

mahendra singh
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to put result of shell function into variable method Beginning VB 6 1 April 20th, 2006 11:42 AM
Query Result to Session Variable johnp ASP.NET 2.0 Basics 1 April 6th, 2006 11:15 PM
pass the result of a query to a variable ... eusebio Pro VB Databases 6 March 30th, 2006 07:41 PM
Query Result mateenmohd SQL Server 2000 0 November 1st, 2003 03:53 AM
Setting a Variable = Result of a SQL Query PeteS VB Databases Basics 1 June 20th, 2003 08:14 AM



All times are GMT -4. The time now is 12:31 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.