Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 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 November 22nd, 2004, 03:56 PM
Authorized User
 
Join Date: Nov 2004
Location: , , .
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default Pass variable to linked server query

I'm having problem with an OpenQuery statement in stored procedure, which should be run on FoxPro linked server. I'm getting either an error messages or not the result I expect. I know that the problem is with WHERE part, without this part it works.


Here is the code:
-------------------------------------
DECLARE @LastDate datetime
SELECT @LastDate = MAX(DateChaged)
FROM tblPersonel
WHERE ACTIVE IN( 'A', 'T')

1. I tried:
SELECT * FROM OPENQUERY(FoxProLink, 'SELECT ACTIVE, EmpNumber FROM tblPersonel WHERE DateChanged >=''+@LastDate+''')

This line gives me an error msg:

Could not execute query against OLE DB provider 'MSDASQL'.
[OLE/DB provider returned message: [Microsoft][ODBC Visual FoxPro Driver]Operator/operand type mismatch.]


2. I tried to use CTOD() - FOXPRO function to convert character to date.

SELECT * FROM OPENQUERY(FoxProLink, 'SELECT ACTIVE, EmpNumber FROM tblPersonel WHERE DateChanged >=CTOD(''+@LastDate+'')')

-this doesn't give any error, but doesn't limit the result set as it should.
Reply With Quote
  #2 (permalink)  
Old November 23rd, 2004, 08:30 AM
Friend of Wrox
 
Join Date: Sep 2004
Location: New Delhi, Dekhi, India.
Posts: 109
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Anantsharma Send a message via Yahoo to Anantsharma
Default

Hi,

I feel the problem is in Passing Parameter. You have defined @LastDate
 as DateTime and trying to pass it in the way of Varchar/Char. You should use CAST / Convert to change the datatype into Varchar.
Here it goes :-

DECLARE @LastDate datetime
SELECT @LastDate = MAX(DateChaged)
FROM tblPersonel
WHERE ACTIVE IN( 'A', 'T')

SELECT * FROM OPENQUERY(FoxProLink, 'SELECT ACTIVE, EmpNumber FROM tblPersonel WHERE DateChanged >='+ CONVERT(VARCHAR(10),@LastDate,110)+'''')

Hope this works.

Gud luck

B. Anant
Reply With Quote
  #3 (permalink)  
Old November 23rd, 2004, 08:37 AM
Friend of Wrox
 
Join Date: Sep 2004
Location: New Delhi, Dekhi, India.
Posts: 109
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Anantsharma Send a message via Yahoo to Anantsharma
Default

HI again,

If your second solution works but giving wrong info, try to use CONVERT to remove time part from @LastDate.

SELECT * FROM OPENQUERY(FoxProLink, 'SELECT ACTIVE, EmpNumber FROM tblPersonel
WHERE
DateChanged >=CTOD(''+Convert(Varchar(10),@LastDate,110)+'') ')

Gud luck



B. Anant
Reply With Quote
  #4 (permalink)  
Old November 23rd, 2004, 11:41 AM
Authorized User
 
Join Date: Nov 2004
Location: , , .
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It didn't work, for OpenQuery I need to use FoxPro functions, since it runs on linked server.
Thanks for your reply.
Reply With Quote
  #5 (permalink)  
Old November 23rd, 2004, 02:38 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Bangalore, KA, India.
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Sofya,

What is the value that comes with @LastDate? You have declared that as datetime, why don't you try declaring it as varchar(10) and pass the value in the right format?

Or try this.
Code:
Declare @strOpenQuery varchar(200)
Select @strOpenQuery = 'SELECT ACTIVE, EmpNumber  FROM tblPersonel WHERE DateChanged >=CTOD(''+ @LastDate + '')'
-- Display @strOpenQuery to see if the value gets substituted fine.
Select @strOpenQuery

SELECT * FROM OPENQUERY(FoxProLink, @strOpenQuery)
Hope that helps.
Cheers!

_________________________
- Vijay G
Strive for Perfection
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
CommandTimeout on query using linked server sjungers Classic ASP Databases 1 February 25th, 2008 03:54 AM
How to pass javascript variable to server side Andraw Classic ASP Basics 17 January 22nd, 2007 01:05 PM
pass java variable to xsl variable kathy1016cats XSLT 1 June 14th, 2006 06:23 PM
pass the result of a query to a variable ... eusebio Pro VB Databases 6 March 30th, 2006 07:41 PM
Can't pass query string variable on secure server gnilly BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 0 August 24th, 2005 11:18 AM



All times are GMT -4. The time now is 05:15 AM.


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