Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 OPENQUERY & sp_executesql & Parameters
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

OscarLG
Starting Member

Spain
2 Posts

Posted - 11/06/2012 :  13:47:03  Show Profile  Reply with Quote
Hi all,

I'm trying to run a query through a linked server using OPENQUERY and sp_executesql because I need one input parameter and an output paramater:

This is my code:


SET @SQLString = N'SELECT @OUT_Num_regs = COUNT(*) from OPENQUERY(MyLinkServer, ''SELECT dvac_007 FROM cron_007 WHERE codi_007 = @IN_Employee'')'
SET @ParmDefinition = N'@IN_Employee varchar(12), @OUT_Num_regs int OUTPUT'

EXECUTE sp_executesql
@SQLString,
@ParmDefinition,
@IN_trabajador = @EMPLOYEE
@OUT_Num_regs = @Num_regs OUTPUT

I get:

OLE DB provider 'MSDASQL' reported an error. The provider did not give any information about the error.

I've been searching this site and I found a lot of good ideas but no one fixed my problem.

Thank you in advance!

Edited by - OscarLG on 11/06/2012 13:50:06

visakh16
Very Important crosS Applying yaK Herder

India
52326 Posts

Posted - 11/06/2012 :  14:51:17  Show Profile  Reply with Quote
shouldnt it be this?

SET @SQLString = N'SELECT @OUT_Num_regs = COUNT(*) from OPENQUERY(MyLinkServer, ''SELECT dvac_007 FROM cron_007 WHERE codi_007 = '' + @IN_Employee)'
SET @ParmDefinition = N'@IN_Employee varchar(12), @OUT_Num_regs int OUTPUT'



------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

OscarLG
Starting Member

Spain
2 Posts

Posted - 11/07/2012 :  07:23:26  Show Profile  Reply with Quote
Thank you Visakh but unfortunately this didn't fixed it...

I tried this and it worked...

SET @SQLString = N'SELECT @OUT_Num_regs = COUNT(*) from OPENQUERY(MyLinkServer, ''SELECT dvac_007 FROM cron_007 WHERE codi_007 = '
SET @SQLString = @SQLString + N'''''' + @EMPLOYEE + ''''''')'
SET @ParmDefinition = N'@OUT_Num_regs int OUTPUT'
EXECUTE sp_executesql
@SQLString,
@ParmDefinition,
@OUT_Num_regs = @Num_regs OUTPUT

Don't ask me to explain it 'cause I don't know how :-(
It was just adding "'" before and after the @EMPLOYEE variable.

Best regards / Un saludo
Oscar L.
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000