Solved

INCORRECT SYNTAX NEAR KEYWORD 'INSERT'

Posted on 2004-09-20
8
745 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
 
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
Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

 
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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Join & Write a Comment

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
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
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now