lindasoph
Technical User
- Jan 27, 2012
- 15
Can't figure out how to correct this error, also is the commit rollback set up correctly could not find verification or example!!
Project Description: Need to run a table (tbl1) of information (ex. Name,Ssn, Amounts) through some joined tables finding out if a record exists. If a record does exists an update to two tables is needed (the update data is amount field). If a record does not exist then the data from tbl1 will be written to another table (tbl2).
Error is
Incorrect syntax near '@hld_tracknum'.
SQL Code where error is occuring:
SELECT *
FROM [XXXX_dev].[dbo].[tblImport] ci
IF ci.TRACKNUM = cs.TRACKNumber
AND ci.ID = cs.Id
AND cs.GDAT <= @LateDate
AND cs.GDAT >= @EarlDate
BEGIN
UPDATE [XXXX_dev].[dbo].[tblModule]
SET cm.decimal02 = ci.ZING
WHERE cs.TRACNUM = ci.TNumber
AND cs.SPECNum = ci.SPN
UPDATE [XXXX_dev].[dbo].[tblSpecial]
SET sn.Notes = ci.CDT
WHERE CustID = 'XXXX'
AND cm.SpecXX = sn.SpecialXX
END
ELSE
@hld_tracknum = ci.TRACKNUM
@hld_gdat = ci.GDAT
@hld_id = ci.ID
@hld_l_name = ci.LNAME
@hld_f_name = ci.FNAME
@hld_zing = ci.ZING
@hld_cdt= ci.CDT
INSERT INTO [XXXX_dev].[dbo].[xxxx_exceptions]
(col1
,col2
,col3
,col4
,col5
,col6
,col7)
VALUES ('@hld_tracknum'
,'@hld_gdat'
,'@hld_id'
,'@hld_l_name'
,'@hld_f_name'
,'@hld_zing'
,'@hld_cdt')
IF @@ERROR = 0
COMMIT TRAN
ELSE
ROLLBACK TRAN
GO
Project Description: Need to run a table (tbl1) of information (ex. Name,Ssn, Amounts) through some joined tables finding out if a record exists. If a record does exists an update to two tables is needed (the update data is amount field). If a record does not exist then the data from tbl1 will be written to another table (tbl2).
Error is
Incorrect syntax near '@hld_tracknum'.
SQL Code where error is occuring:
SELECT *
FROM [XXXX_dev].[dbo].[tblImport] ci
IF ci.TRACKNUM = cs.TRACKNumber
AND ci.ID = cs.Id
AND cs.GDAT <= @LateDate
AND cs.GDAT >= @EarlDate
BEGIN
UPDATE [XXXX_dev].[dbo].[tblModule]
SET cm.decimal02 = ci.ZING
WHERE cs.TRACNUM = ci.TNumber
AND cs.SPECNum = ci.SPN
UPDATE [XXXX_dev].[dbo].[tblSpecial]
SET sn.Notes = ci.CDT
WHERE CustID = 'XXXX'
AND cm.SpecXX = sn.SpecialXX
END
ELSE
@hld_tracknum = ci.TRACKNUM
@hld_gdat = ci.GDAT
@hld_id = ci.ID
@hld_l_name = ci.LNAME
@hld_f_name = ci.FNAME
@hld_zing = ci.ZING
@hld_cdt= ci.CDT
INSERT INTO [XXXX_dev].[dbo].[xxxx_exceptions]
(col1
,col2
,col3
,col4
,col5
,col6
,col7)
VALUES ('@hld_tracknum'
,'@hld_gdat'
,'@hld_id'
,'@hld_l_name'
,'@hld_f_name'
,'@hld_zing'
,'@hld_cdt')
IF @@ERROR = 0
COMMIT TRAN
ELSE
ROLLBACK TRAN
GO