Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
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 July 3rd, 2007, 12:24 AM
Registered User
 
Join Date: Dec 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default storing fields values in variable from openqury

Hi All

I am facing a problem while executing the following openquery statement I need to store fields values in variables '@DOCNBR' and '@FISCALNO'



SET @SQL = ' SELECT DOCNBR, FISCALNO FROM PJLABHDR WHERE EMPLOYEE ='
+ dbo.quotestring(@pstrEmployeeID) + ''
 SET @SQL= @SQL + ' AND PE_DATE = ' + dbo.quotestring(@pdtWeekEndingDate)
 SET @SQL= @SQL + ' AND LE_STATUS = ''C'' AND LE_TYPE = ''R'''

SET @SQL=N'EXEC sp_executesql select @strDocnbr = DOCNBR, @strFiscalNo = FISCALNO FROM openquery(ORION, ' + dbo.quotestring(@SQL) + ')'


exec (@sql)


for your ref 'dbo.quotestring()' is a function that returns a quoted string..

Help me plz
 
Old July 12th, 2007, 02:42 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

You can't do it that way, as the variables here have transaction scope and the variables cannot be used outside, in case of dynamic string execution using "exec (@sql)". You need to find alternate way to do that.

_________________________
- Vijay G
Strive for Perfection





Similar Threads
Thread Thread Starter Forum Replies Last Post
Storing data to a variable Mikect VB Databases Basics 1 April 16th, 2007 01:53 PM
storing Javascript variable to ASP variable rupen Classic ASP Basics 5 April 10th, 2007 07:06 AM
Storing Data in Memo Fields! tks_muthu Classic ASP Databases 2 April 11th, 2005 02:07 AM
Storing Calculated Fields dearnne Access 3 September 2nd, 2004 05:30 PM
Storing Calculated Fields dearnne Access VBA 1 August 30th, 2004 10:54 AM





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