I created a stored procedure that will have two queries, those two queries will update records in two tables.
So I will mention what it shows
My procedure is like below
ALTER PROC UpdateMissingItemONPoe
@StoreID INT,
@Name VARCHAR(20)
AS
BEGIN
DECLARE @UpdateRec NVARCHAR(MAX) = '';
DECLARE @StoreIP SYSNAME = ''
SET @StoreIP = CASE @StoreID
WHEN 1111 THEN '[192.168.1.45].[Store1].[dbo]'
WHEN 2222 THEN '[192.168.2.45].[Store2].[dbo]'
WHEN 3333 THEN '[192.168.3.45].[Store3].[dbo]'
END
SET @UpdateRec = N' IF((SELECT NameID from '+@StoreIP+'.Details WHERE Name = '''+@Name+''') = 2 )
BEGIN
INSERT INTO ' + @StoreIP + '.PurchaseOrderEntry(
/* InsertField Name */
)
select
Name,
Standard,
Department,
Category,
SubDescription,
Rank
from
'+@StoreIP+'.Details
where
Name = '''+@Name+'''
INSERT INTO '+@StoreIP+'.HeadQuarter(
/* InsertField Name */
)
select
Name,
Standard,
Department,
Category,
SubDescription,
Rank
from
'+@StoreIP+'.Details
where
Name = '''+@Name+'''
END'
print @UpdateRec
EXEC sp_executesql @UpdateRec
END
When I execute this stored procedure, it is not showing any error message. But, that dynamic query is not having complete query when I print.
Printed query is like
INSERT INTO '+@StoreIP+'.PurchaseOrderEntry(
/* InsertField Name */
)
select
Name,
Standard,
Department,
Category,
SubDescription,
Rank
from
'+@StoreIP+'.Details
where
Name = '''+@Name+'''
INSERT INTO '+@StoreIP+'.HeadQuarter(
/* InsertField Name */
)
select
Name,
Standard,
Department,
Category,
The remaining lines are missing