Solved

INCORRECT SYNTAX NEAR KEYWORD 'INSERT'

Posted on 2004-09-20
8
757 Views
Last Modified: 2012-06-27
I have an ADP and I am trying to run an Insert query (from a view).  I get the message:
INCORRECT SYNTAX NEAR KEYWORD 'INSERT'

Here is my code:

INSERT INTO tblICInventory
                      ([strProductID], [strVendorNumber], [strManufactureNumber], [memDescription], [memPODescription], [strStatus], [ysnTrackStock], [strManufacture],
                      [strCurrencyID], [strItemClass], [curCost], [curCurrentCost], [curSalesPrice], [strUnitMeasure], [strUPCCode], [strCategory], [strCategory2],
                      [strCostMethod], [dtmDateEntered], [dtmLastModified], [dtmPosted], [dblRetailPrice], [dblSuggestedRetailPrice], [strPricing])
SELECT     [dbo].[tblEPIC].[UPC], [dbo].[tblEPIC].[Catalog Number], [dbo].[tblEPIC].[Catalog Number], [dbo].[tblEPIC].[Description],
                      [dbo].[tblEPIC].[Legacy Description],
                      CASE [dbo].[tblEPIC].[Chg] WHEN 'D' THEN 'Discontinued' WHEN 'U' THEN 'Phase Out' WHEN 'Q' THEN 'Discontinued' ELSE 'Active' END, - 1,
                      [dbo].[tblEPIC].[Manufacturer], 'USD', 'Stock', [dbo].[tblEPIC].[Cost], [dbo].[tblEPIC].[Cost], [dbo].[tblEPIC].[Col_ 3 Price],
                      CASE [dbo].[tblEPIC].[Unit] WHEN 'E' THEN 'Each' WHEN 'C' THEN 'Hundred' WHEN 'M' THEN 'Thousand' ELSE '' END, [dbo].[tblEPIC].[UPC],
                      [dbo].[tblICCategory].[strCategory], [dbo].[tblICCategory2].[strCategory2], 'Average Cost', { fn NOW() }, { fn NOW() }, { fn NOW() },
                      [dbo].[tblEPIC].[Retail Price], [dbo].[tblEPIC].[Col_ 3 Price], 'None'
FROM         [dbo].[tblEPIC] INNER JOIN
                      [dbo].[tblICCategory] INNER JOIN
                      [dbo].[tblICCategory2] ON [dbo].[tblICCategory].[strCategory] = [dbo].[tblICCategory2].[strCategory] ON
                      [dbo].[tblEPIC].[Item Class] = [dbo].[tblICCategory2].[strDescription2]

Can anyone help?
0
Comment
Question by:codeguy
  • 4
  • 2
  • 2
8 Comments
 
LVL 15

Expert Comment

by:jdlambert1
ID: 12107550
1. What is an ADP?
2. NOW is not a valid function in T-SQL, the T-SQL equivalent is GetDate():
...  'Average Cost', GetDate(), GetDate(), GetDate(), [dbo].[tblEPIC].[Retail Price],  ...
0
 
LVL 15

Expert Comment

by:jdlambert1
ID: 12107556
Also, what do you mean you're trying to run this "from a view"?
0
 

Author Comment

by:codeguy
ID: 12107580
An ADP (Access Data Project) is just an access file that connects to SQL Server.  I can either create queries/views or run a stored procedure.  I changed the functions to GetDate and got the same message.
 
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 15

Expert Comment

by:jdlambert1
ID: 12107610
Yeah, GetDate fixed what would have been your next problem. The problem isn't the syntax, as far as SQL Server's concerned, so it has to be the context. Exactly how are you trying to execute this?
0
 
LVL 9

Accepted Solution

by:
paelo earned 125 total points
ID: 12107611
Views cannot contain the INSERT or UPDATE syntax, only SELECT queries.  You will want to put this within a stored proc, I think.

-Paul.
0
 

Author Comment

by:codeguy
ID: 12107635
Thanks Paul:

Can you help with the SP syntax???
0
 
LVL 15

Expert Comment

by:jdlambert1
ID: 12107666
If executed from Query Analyzer to create a stored procedure in SQL Server:

CREATE PROCEDURE up_InsertICInventory AS

INSERT INTO tblICInventory
  ([strProductID], [strVendorNumber], [strManufactureNumber], [memDescription], [memPODescription], [strStatus], [ysnTrackStock], [strManufacture],
  [strCurrencyID], [strItemClass], [curCost], [curCurrentCost], [curSalesPrice], [strUnitMeasure], [strUPCCode], [strCategory], [strCategory2],
  [strCostMethod], [dtmDateEntered], [dtmLastModified], [dtmPosted], [dblRetailPrice], [dblSuggestedRetailPrice], [strPricing])
SELECT [dbo].[tblEPIC].[UPC], [dbo].[tblEPIC].[Catalog Number], [dbo].[tblEPIC].[Catalog Number], [dbo].[tblEPIC].[Description],
  [dbo].[tblEPIC].[Legacy Description], CASE [dbo].[tblEPIC].[Chg] WHEN 'D' THEN 'Discontinued' WHEN 'U' THEN 'Phase Out' WHEN 'Q' THEN 'Discontinued' ELSE 'Active' END, - 1,
  [dbo].[tblEPIC].[Manufacturer], 'USD', 'Stock', [dbo].[tblEPIC].[Cost], [dbo].[tblEPIC].[Cost],
  [dbo].[tblEPIC].[Col_ 3 Price], CASE [dbo].[tblEPIC].[Unit] WHEN 'E' THEN 'Each' WHEN 'C' THEN 'Hundred' WHEN 'M' THEN 'Thousand' ELSE '' END, [dbo].[tblEPIC].[UPC],
  [dbo].[tblICCategory].[strCategory], [dbo].[tblICCategory2].[strCategory2], 'Average Cost', GetDate(), GetDate(), GetDate(),
  [dbo].[tblEPIC].[Retail Price], [dbo].[tblEPIC].[Col_ 3 Price], 'None'
FROM [dbo].[tblEPIC] INNER JOIN
  [dbo].[tblICCategory] INNER JOIN
  [dbo].[tblICCategory2] ON [dbo].[tblICCategory].[strCategory] = [dbo].[tblICCategory2].[strCategory] ON
  [dbo].[tblEPIC].[Item Class] = [dbo].[tblICCategory2].[strDescription2]
0
 
LVL 9

Expert Comment

by:paelo
ID: 12107711
Stored procedures can handle one or more statements (like jdlambert's example above) and can also take parameters like this:

CREATE PROC dbo.procTemp (
 @var1 varchar(20),
 @var2 int,
 @var3 datetime
)
AS
BEGIN

...T-SQL...

END


-Paul.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question