Wrox Programmer Forums
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 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 6th, 2004, 12:24 PM
Registered User
 
Join Date: Apr 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Dynamic query problem

Is it possible to return a declared variable value from a dynamic query. For example using the following code extract...

BEGIN
SET @cmd =
'SELECT ' + CONVERT(nvarchar,@CloumnName) +
' AS colourCost, 0 AS runOnCost ' +
' FROM [user].' + CONVERT(nvarchar,@tableName) +
' WHERE quantity=' + CONVERT(nvarchar,@quantity)
SET NOCOUNT OFF
EXEC(@cmd)
END

I would like to achieve the following.....

BEGIN
SET @cmd =
'SELECT ' + CONVERT(nvarchar,@CloumnName) +
' AS @GetValue = colourCost, 0 AS runOnCost ' +
' FROM [user].' + CONVERT(nvarchar,@tableName) +
' WHERE quantity=' + CONVERT(nvarchar,@quantity)
SET NOCOUNT OFF
EXEC(@cmd)
END
I have tried various approaches using temporary tables,
I am aware of the benifits of using sp_executesql.
If there is a solution to this please let me know.

 
Old April 6th, 2004, 01:16 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

I have tried this too to no avail myself, but I'm not sure of all the possibilities.
 
Old April 6th, 2004, 11:55 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default

I myself use this [u]TEXT&EXECUTE</u> method when I want to wok with dynamic query! I think that its the efficient way?!

Always:),
Hovik Melkomian.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic SQL Query Problem HydroChronic Access VBA 10 October 4th, 2007 09:27 AM
Dynamic Query Sum Colonel Angus SQL Server 2000 4 March 30th, 2005 11:08 AM
Dynamic Query ninel SQL Server 2000 1 March 8th, 2005 01:18 AM
Dynamic Query zaman1111 Javascript 4 August 4th, 2004 02:16 PM
ADO Dynamic Query - Please help rudidoku Access 1 July 23rd, 2003 06:50 PM





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