Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2005 > SQL Server 2005
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 5th, 2008, 03:43 AM
Registered User
 
Join Date: Apr 2008
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
 
Old April 7th, 2008, 03:41 AM
Authorized User
 
Join Date: Jun 2003
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
 
Old April 7th, 2008, 04:04 AM
Registered User
 
Join Date: Apr 2008
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





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





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