In Progress

Fix a T-SQL process for MS-SQL

I am getting an error with this T-SQL process I am writing. I have never worked with OPENROWSET and it shows. It needs to loop though a table from one database to get the databasename,user, pass and serverr info to open that database then do an update. Here is the code and the error.

--start process 104 UNFI PA

DECLARE @instanceName VARCHAR(50)

DECLARE @dbName VARCHAR(50)

DECLARE @dbUserName VARCHAR(50)

DECLARE @dbPassword VARCHAR(250)

DECLARE @vendorId INT

DECLARE @processStart DATETIME

DECLARE @processEnd DATETIME

DECLARE @sqlParent NVARCHAR(4000)

DECLARE @sqlQuery NVARCHAR(4000)

SET @sqlParent =' update product set ProductCount=((select sum(Inventory) from Product_Cost where ProductID=[url removed, login to view])) where ((select count(id) from Product_Cost where productID=[url removed, login to view] ) > 0)

FROM OPENROWSET (''SQLNCLI'', ''Server=<<INSTANCENAME>>;Database=<<DBNAME>>;Uid=<<USERNAME>>;Pwd=<<PASSWORD>>'') d'

DECLARE cDetail CURSOR FAST_FORWARD READ_ONLY

FOR

SELECT DB_IPAddress, [DB_Name], DB_UserName, DB_Pass, VendorID --, process_Start, process_End

FROM

OPENROWSET('SQLNCLI','Server=XXXXXXXXXXXXXXX;Database=XXXXXXXXXXXXXXX;Uid=XXXXXXXXXXXXXXX;XXXXXXXXXXXXXXX',

'select top 1 * from Customer_ImportFeeds where active = 0 and feedid = 104 and vendorid <> 0') as a

OPEN cDetail

FETCH cDetail INTO @instanceName, @dbName, @dbUserName, @dbPassword, @vendorId

WHILE @@FETCH_STATUS = 0 BEGIN

SET @sqlQuery = @sqlParent

SET @sqlQuery = REPLACE(@sqlQuery, '<<INSTANCENAME>>', @instanceName)

SET @sqlQuery = REPLACE(@sqlQuery, '<<DBNAME>>', @dbName)

SET @sqlQuery = REPLACE(@sqlQuery, '<<USERNAME>>', @dbUserName)

SET @sqlQuery = REPLACE(@sqlQuery, '<<PASSWORD>>', @dbPassword)

SET @sqlQuery = REPLACE(@sqlQuery, '<<VENDORID>>', @vendorId)

PRINT @instanceName + ', ' + @dbName + ': '

PRINT @sqlQuery

EXEC sp_executesql @sqlQuery

FETCH cDetail INTO @instanceName, @dbName, @dbUserName, @dbPassword, @vendorId

END

CLOSE cDetail

DEALLOCATE cDetail

-------------------------------------------------

ERROR:

Msg 156, Level 15, State 1, Line 2

Incorrect syntax near the keyword 'FROM'.

Skills: Microsoft SQL Server, SQL

See more: ms sql server t sql freelancing, classic asp ms sql, blurple offer ms sql, automatic backup ms sql express, asp net fileupload log ms sql, asp ms sql data, android sql count table entries, access sql count, software write mq4, software write chip epson, useful software write book, sql count year hired employees, software write web specs, sql count aging date, sql count age using date birth, free software write user guide, software write edid, sql count running total, free software write company profile, software write websites idea, sql count stock status, software write book images, oracle sql count age, software write books, software write protection

About the Employer:
( 5 reviews ) Alpharetta, United States

Project ID: #12243805

Awarded to:

$155 USD in 0 days
(1 Review)
2.4

6 freelancers are bidding on average $135 for this job

mehulprajapati91

Dear Hiring Manager, I am professional software,website & mobile app. developer.I can start working as soon as possible. [url removed, login to view] -- My previously Worked proje More

$111 USD in 3 days
(6 Reviews)
2.9
$155 USD in 3 days
(2 Reviews)
1.3
enragetech

I have carefully gone through your job posting on “Fix a T-SQL process for MS-SQL”. I ’m an expert in web development with more than 5 years experiences. I am expert in skills like php, javascript, hquery, html5 and cs More

$155 USD in 1 day
(0 Reviews)
0.0
$155 USD in 3 days
(0 Reviews)
0.0
xlokks

We have 1000+ employees in our company. So we can do all kind of IT project in any languages and all stream. We have 3 years+ experience employees for all streams especially C PROGRAMMING, C++,C#, , HTML,HTML5,WORDPRE More

$138 USD in 7 days
(0 Reviews)
0.0
$77 USD in 3 days
(0 Reviews)
0.0