Solved

INCORRECT SYNTAX NEAR KEYWORD 'INSERT'

Posted on 2004-09-20
8
762 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

739 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