Click here to Skip to main content
15,911,030 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have is query. That I'm getting an error message "Msg 156, Level 15, State 1, Line 23
Incorrect syntax near the keyword 'FROM'." It is pointing to the query "FROM [TOMSQLVISION].[VISION_2020].[REAL_PROP].[VW_HSALE]." This query pulls in data from 1 sql server and creates a table in another sql server. Then populates a web page.


SQL
  1  DROP TABLE [dbo].[VISION_SALEHIST4]
  2  SELECT 
  3  
  4    MNC,
  5    PID,
  6    LINE_NUM,
  7    BOOK_PG,
  8    CONVERT(datetime, SALEDATE) AS SALEDATE,
  9    SALEPRICE,
 10    CERTIFICATE,
 11    INSTRUMENT,
 12    QUALIFIED,
 13    OWN_NAME,
 14    CO_OWN_NAME,
 15    ADDRESS1,
 16    ADDRESS2,
 17    CITY,
 18    STATE,
 19    ZIP
 20    
 21  INSERT INTO [dbo].[VISION_SALEHIST4]
 22   
 23    FROM [TOMSQLVISION].[VISION_2020].[REAL_PROP].[VW_HSALE]


What I have tried:

I'm connected to the other server tomsqlvision. The table that query is pullilng the data from is a view table. Would that make a difference?

Thanks for the help.
Posted
Updated 10-Aug-20 10:08am
v2
Comments
[no name] 10-Aug-20 14:59pm    
Think about INSERT INTO <table> (<columns>) SELECT <columns> ... FROM ...

Read this: SQL INSERT INTO Statement[^]
[no name] 10-Aug-20 15:14pm    
[no name] 10-Aug-20 15:16pm    
Sorry some inter...whatever... what I mean is something like
INSERT INTO [dbo].[VISION_SALEHIST4] (<columns>) SELECT <columns> FROM [TOMSQLVISION].[VISION_2020].[REAL_PROP].[VW_HSALE]

[Edit]
And DROP TABLE [dbo].[VISION_SALEHIST4]is a bad idea without to create it again before try to insert.

Either you create the table again or instead of drop table you do this
DELETE FROM [dbo].[VISION_SALEHIST4]
Jassom 10-Aug-20 15:25pm    
You dropped the table at first .. and then how would you insert values into a dropped table???
[no name] 10-Aug-20 15:27pm    
Yep ;)

1 solution

You may find what you want in the link below:

sql - INSERT INTO from two different server database - Stack Overflow[^]


try it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900