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

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Update From OPENQUERY
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

poser
Posting Yak Master

124 Posts

Posted - 02/11/2013 :  09:09:15  Show Profile  Reply with Quote
Good morning!
I'm trying to insert into a sql table from and linked oracle server using openquery.
I tried the Insert and the Update and bot error out..

Insert into SQLTable
From openquery (linkedserver, 'select lname, fname, address from
TACK.T_Tack')

Thank you for any help you can give me in this..
R/P

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 02/11/2013 :  10:26:48  Show Profile  Reply with Quote
whats the error? please post exact error message

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

Go to Top of Page

poser
Posting Yak Master

124 Posts

Posted - 02/11/2013 :  10:36:49  Show Profile  Reply with Quote
My exact update statement:

UPDATE SQLTable
From openquery (linkedserver, 'select lname, fname, address from
TACK.T_Tack')

I'm getting a syntax error:
Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword 'FROM'.

Thank you for helping with this!
R/p
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 02/11/2013 :  10:40:05  Show Profile  Reply with Quote
it should be like

UPDATE t
SET t.field1 = ...,
t.Field2 = ...
From SQLTable t
INNER JOIN openquery (linkedserver, 'select lname, fname, address from
TACK.T_Tack')q
ON.... condition


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

Go to Top of Page

poser
Posting Yak Master

124 Posts

Posted - 02/11/2013 :  11:12:10  Show Profile  Reply with Quote
Will this work if I truncate this table before load?
Thats all I'm trying to do is to load the oracle data into an empty SQL table daily.
SELECT INTO wouldn't work because the table in sql already existed.
Thanks, p
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 02/11/2013 :  23:07:22  Show Profile  Reply with Quote
quote:
Originally posted by poser

Will this work if I truncate this table before load?
Thats all I'm trying to do is to load the oracle data into an empty SQL table daily.
SELECT INTO wouldn't work because the table in sql already existed.
Thanks, p


nope...it wont

UPDATE means modifying existing data. If data is not there anymore you cant modify

in that case what you should be using is INSERT...SELECT

ie

INSERT INTO SQLTable(columns...)
SELECT columns...
FROM openquery (linkedserver, 'select lname, fname, address from
TACK.T_Tack')q



make sure you replace columns placeholder with actual column names

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

Go to Top of Page

poser
Posting Yak Master

124 Posts

Posted - 02/12/2013 :  08:44:08  Show Profile  Reply with Quote
Thank you so much!!!
R/p
Go to Top of Page
  Previous Topic Topic Next Topic  
 New 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