SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


how to use opendatasource for exec sp with output parameter


how to use opendatasource for exec sp with output parameter

Author
Message
elham_azizi_62
elham_azizi_62
Old Hand
Old Hand (393 reputation)Old Hand (393 reputation)Old Hand (393 reputation)Old Hand (393 reputation)Old Hand (393 reputation)Old Hand (393 reputation)Old Hand (393 reputation)Old Hand (393 reputation)

Group: General Forum Members
Points: 393 Visits: 820
hello all.
I wanna execute sp with output parameter by use opendatasource.i use this script for it:
exec('exec OPENDATASOURCE(''sqloledb'',''Data Source=ip; User ID=sa;Password=123'').documentdatabase.dbo.GLB_ConcatUploadedFilePart''' +@TBL_UserID+''','+@TBL_IdBody+'output')
and type of @TBL_IdBody is varbinary(max).when execute

declare @TBL_IdBody varbinary(max),@TBL_UserID int
set @TBL_UserID=1
set @TBL_IdBody=cast('' as varbinary(max))
exec('exec OPENDATASOURCE(''sqloledb'',''Data Source=192.168.1.102; User ID=sa;Password=123abc%'').documentdatabase.dbo.GLB_ConcatUploadedFilePart''' +@TBL_UserID+''','+@TBL_IdBody +'output')
select @TBL_IdBody

get error:Implicit conversion from data type nvarchar to varbinary(max) is not allowed. Use the CONVERT function to run this query.

what do i do for solve this problem?how to use opendatasource for exec sp with output parameter?
Erland Sommarskog
Erland Sommarskog
SSCrazy
SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)

Group: General Forum Members
Points: 2157 Visits: 872
So the simplest would be to defined a linked server, then you would not need to use dynamic SQL, but you could make a plain procedure call.

But to continue on the track where you are right now, you could use sp_executesql instead. See my article on dynamic SQL for details:
http://www.sommarskog.se/dynamic_sql.html

Erland Sommarskog, SQL Server MVP, www.sommarskog.se
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search