Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Insert syntax error

Author  Topic 

snufse
Constraint Violating Yak Guru

469 Posts

Posted - 2008-12-01 : 11:57:04
I'm getting an "insert" error running this query from the analyzer. I cannot figure out what the issue is:

declare @JobNumber int
declare @JobNumber1 char(12)
set @JobNumber = 1100281
set @JobNumber1 = ' 1100281'

CREATE TABLE #Equential_JobQtyTable
( eq_cost_code nvarchar(15) unique,
eq_item_name char(30),
eq_sum_qty decimal(8,2)
)

CREATE TABLE #JDE_JobQtyTable
( jde_cost_code nvarchar(15) unique,
jde_sum_qty decimal(8,2)
)

CREATE TABLE #JDE_JobName
( jde_cost_code nvarchar(15) unique,
jde_name char(30),
jde_uom char(2)
)

CREATE TABLE #Combined_JobQtyTable
( costcode nvarchar(15) unique,
itemname char(30),
eqsumqty decimal(8,2),
jdesumqty decimal(8,2),
differenceqty decimal(8,2),
jdeuom char(2)
)

insert into #Equential_JobQtyTable
exec [VGIWPW03-SQL3\EQUENTIALPROD].goLabor30.dbo.sp_Vecellio_ProductionInquiry @JobNumber

Exec ('Call QGPL.get_jobqty(?)', @JobNumber1) AT AS400SRV_MSDASQL
insert into #JDE_JobQtyTable

Exec ('Call QGPL.get_jobnam(?)', @JobNumber1) AT AS400SRV_MSDASQL
insert into #JDE_JobName

insert into #Combined_JobQtyTable(costcode, itemname, eqsumqty)
select eq_cost_code, eq_item_name, eq_sum_qty
from #Equential_JobQtyTable

update #Combined_JobQtyTable
set jdesumqty = #JDE_JobQtyTable.jde_sum_qty, differenceqty = (eqsumqty - #JDE_JobQtyTable.jde_sum_qty)
from #Combined_JobQtyTable, #JDE_JobQtyTable
where #Combined_JobQtyTable.costcode = #JDE_JobQtyTable.jde_cost_code

insert into #Combined_JobQtyTable (costcode, jdesumqty, differenceqty)
select distinct t2.jde_cost_code, t2.jde_sum_qty, t2.jde_sum_qty * -1
from #JDE_JobQtyTable AS t2
where not exists (select * from #Combined_JobQtyTable AS t1 where t1.costcode = t2.jde_cost_code and t1.jdesumqty = t2.jde_sum_qty)

update #Combined_JobQtyTable
set itemname = #Jde_JobName.jde_name, jdeuom = #JDE_JobName.jde_uom
from #Combined_JobQtyTable, #JDE_JobName
where #Combined_JobQtyTable.costcode = #JDE_JobName.jde_cost_code

select *
from #Combined_JobQtyTable
order by costcode

drop table #Equential_JobQtyTable
drop table #JDE_JobQtyTable
drop table #Combined_JobQtyTable
drop table #JDE_JobName



The error is:

Msg 156, Level 15, State 1, Line 41
Incorrect syntax near the keyword 'insert'.

Shamil
Starting Member

5 Posts

Posted - 2008-12-01 : 12:03:38
declare @JobNumber int
declare @JobNumber1 char(12)
set @JobNumber = 1100281
set @JobNumber1 = ' 1100281'

CREATE TABLE #Equential_JobQtyTable
( eq_cost_code nvarchar(15) unique,
eq_item_name char(30),
eq_sum_qty decimal(8,2)
)

CREATE TABLE #JDE_JobQtyTable
( jde_cost_code nvarchar(15) unique,
jde_sum_qty decimal(8,2)
)

CREATE TABLE #JDE_JobName
( jde_cost_code nvarchar(15) unique,
jde_name char(30),
jde_uom char(2)
)

CREATE TABLE #Combined_JobQtyTable
( costcode nvarchar(15) unique,
itemname char(30),
eqsumqty decimal(8,2),
jdesumqty decimal(8,2),
differenceqty decimal(8,2),
jdeuom char(2)
)

insert into #Equential_JobQtyTable
exec goLabor30.dbo.sp_Vecellio_ProductionInquiry @JobNumber

insert into #JDE_JobQtyTable
Exec ('Call QGPL.get_jobqty(?)', @JobNumber1) AT AS400SRV_MSDASQL

insert into #JDE_JobName
Exec ('Call QGPL.get_jobnam(?)', @JobNumber1) AT AS400SRV_MSDASQL


insert into #Combined_JobQtyTable(costcode, itemname, eqsumqty)
select eq_cost_code, eq_item_name, eq_sum_qty
from #Equential_JobQtyTable

update #Combined_JobQtyTable
set jdesumqty = #JDE_JobQtyTable.jde_sum_qty, differenceqty = (eqsumqty - #JDE_JobQtyTable.jde_sum_qty)
from #Combined_JobQtyTable, #JDE_JobQtyTable
where #Combined_JobQtyTable.costcode = #JDE_JobQtyTable.jde_cost_code

insert into #Combined_JobQtyTable (costcode, jdesumqty, differenceqty)
select distinct t2.jde_cost_code, t2.jde_sum_qty, t2.jde_sum_qty * -1
from #JDE_JobQtyTable AS t2
where not exists (select * from #Combined_JobQtyTable AS t1 where t1.costcode = t2.jde_cost_code and t1.jdesumqty = t2.jde_sum_qty)

update #Combined_JobQtyTable
set itemname = #Jde_JobName.jde_name, jdeuom = #JDE_JobName.jde_uom
from #Combined_JobQtyTable, #JDE_JobName
where #Combined_JobQtyTable.costcode = #JDE_JobName.jde_cost_code

select *
from #Combined_JobQtyTable
order by costcode

drop table #Equential_JobQtyTable
drop table #JDE_JobQtyTable
drop table #Combined_JobQtyTable
drop table #JDE_JobName
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-01 : 12:27:41
isnt this same as?

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=115431
Go to Top of Page

snufse
Constraint Violating Yak Guru

469 Posts

Posted - 2008-12-01 : 13:12:02
Yes, my fault, double post
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-01 : 13:15:58
quote:
Originally posted by snufse

Yes, my fault, double post


ok..please in future refrain from cross post.
b/w did your prblm get solved?
Go to Top of Page

snufse
Constraint Violating Yak Guru

469 Posts

Posted - 2008-12-01 : 13:21:52
Not really. I thought I had the solution but will work on it. Thank you.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-01 : 23:41:58
Ok...Let us know if you find any more issues.
Go to Top of Page
   

- Advertisement -