Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...It is good to know that there are groups such as this willing to share knowledge in this money driven economy..."

Geography

Where in the world do Tek-Tips members come from?

OPENQUERY SYNTAX-INSERTING INTO TABLE FROM LINKED SERVERS

eshie003 (Programmer)
23 Apr 12 14:52
I am trying to create a new table within my SQL SVR database [Medicaid_Retro] called [UNM_Claims_REFERRAL_1] based on SQL SVR table [UNM_Claims_REFERRAL] and joining to Oracle via linked server NMPSEDW.  Using the code below, I get the following error: "Invalid object name 'Medicaid_Retro.dbo.UNM_Claims_REFERRAL_1"

What is the proper syntax??

INSERT INTO [Medicaid_Retro].[dbo].[UNM_Claims_REFERRAL_1]
SELECT * FROM [Medicaid_Retro].[dbo].[UNM_Claims_REFERRAL] A,
(SELECT * FROM OPENQUERY(NMPSEDW,'SELECT CLM_SRVC_SRC_MBR_ID,
PROV_TAX_ID,CLM_SRVC_UMREF_ID,CLM_SRVC_PROC_CD,CLM_AUD_NBR,
CLM_AUD_LN_NBR
FROM PSDW.TB_PS_FCET_CLM_SRVC')) B
WHERE A.[Claim ID]=B.CLM_AUD_NBR
AND A.[Line_NO]=B.CLM_AUD_LN_NBR
gmmastros (Programmer)
23 Apr 12 14:55
Does the select query work if you remove the top line (INSERT INTO)?
 

-George
Microsoft SQL Server MVP
My Blogs
SQLCop
twitter
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom

eshie003 (Programmer)
23 Apr 12 15:06
yes, the select statement does work
gmmastros (Programmer)
23 Apr 12 15:50
Try...

CODE

SELECT *
INTO [Medicaid_Retro].[dbo].[UNM_Claims_REFERRAL_1]
FROM [Medicaid_Retro].[dbo].[UNM_Claims_REFERRAL] A,
(SELECT * FROM OPENQUERY(NMPSEDW,'SELECT CLM_SRVC_SRC_MBR_ID,
PROV_TAX_ID,CLM_SRVC_UMREF_ID,CLM_SRVC_PROC_CD,CLM_AUD_NBR,
CLM_AUD_LN_NBR
FROM PSDW.TB_PS_FCET_CLM_SRVC')) B
WHERE A.[Claim ID]=B.CLM_AUD_NBR
AND A.[Line_NO]=B.CLM_AUD_LN_NBR

If the table does not exist, "Select into" will create it.  If the table already exists, then you need to use "Insert Into Select".

Make sense?

-George
Microsoft SQL Server MVP
My Blogs
SQLCop
twitter
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom

eshie003 (Programmer)
23 Apr 12 15:57
It works!  Thanks so much..I knew the syntax was incorrect and couldn't figure it out.  You are the best!

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close