Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 12890

create stored procedure to execute on a remote machine

$
0
0

Hi, I am using the below query and works fine.

DECLARE @ProductName nvarchar(250) = 'Camera', @ProductDescription nvarchar(250) = 'DSLR camera'

DECLARE @query NVARCHAR(MAX)

    SET @query = 'EXEC (''INSERT INTO [dbo].[Products] ([ProductName], [ProductDescription]) VALUES (?,?)'',''' + @ProductName + ''',''' + @ProductDescription + ''') AT [linkedserver]'   PRINT @query -- EXEC ('INSERT INTO [dbo].[Products] ([ProductName], [ProductDescription]) VALUES (?,?)','Camera','DSLR camera') AT [linkedserver]

But when I try to write the same query as a stored procedure and do a jdbc call the stored procedure does nothing.

CREATE PROCEDURE [dbo].[testsp] @ProductName nvarchar(250), @ProductDescription nvarchar(250)
AS

DECLARE @query NVARCHAR(MAX)

    SET @query = 'EXEC (''INSERT INTO [dbo].[Products] ([ProductName], [ProductDescription]) VALUES (?,?)'',''' + @ProductName + ''',''' + @ProductDescription + ''') AT [linkedserver]'   EXEC sp_executesql @stmt = @query

In the javascript application call the stored procedure as below.

call [dbo].[testsp](?,?)

The stored procedure does not throw any errors as such nor does it insert data. Could please point me if I am missing something.

Thank you in advance.


SQLEnthusiast


Viewing all articles
Browse latest Browse all 12890


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>