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
 General SQL Server Forums
 New to SQL Server Programming
 Incorrect Syntax near the keyword left

Author  Topic 

Vack
Aged Yak Warrior

530 Posts

Posted - 2012-04-18 : 14:27:02
Not sure why I'm getting "Incorrect Syntax near the keyword left"




Use [Data_09]
GO
--
--Print the Date and Time
--
PRINT ' '
PRINT GETDATE()
--
--Drop the link and start from scratch
--
--
Print ' '
Print ' Dropping the Linked Excel Connection to prepare for a new connection...'
Print ' ** Msg15015 indicates the link has alread been dropped...THIS IS OK **'
--
EXEC sp_dropserver 'PriceDataBase', 'droplogins'

--
--Build the link to the Excel Spreadsheet
--
--
Print ' '
Print ' Building the Linked Excel Connection...'
--
EXEC sp_addlinkedserver 'PriceDataBase',
@srvproduct = '',
@provider = 'Microsoft.Jet.OLEDB.4.0',
@datasrc = 'C:\PHDPRICES\PHDPriceCode1.xls',
@provstr = 'Excel 8.0;'
GO


--
--Log in to the Spreadsheet
--
--
Print ' '
Print ' Logging into the Linked Excel Connection...'
--
EXEC sp_addlinkedsrvlogin 'PriceDataBase', 'false'
GO
--
--
Print ' '
Print ' Retrive the Selection Criteria from the Excel Spreadsheet...'
--
DECLARE @Type varchar(30)
DECLARE @Customer varchar(30)
DECLARE @ItemNumber varchar(30)
SELECT TOP 1 @Type = cd_tp, @Customer = cd_tp_1_cust_no, @ItemNumber = cd_tp_1_item_no
FROM PriceDataBase...PriceCode1Send$
WHERE cd_tp is not NULL


SELECT @Type = RTRIM(@Type)
SELECT @Customer = RTRIM(@Customer)
SELECT @ItemNumber = RTRIM(@ItemNumber)




Print @Type
Print @Customer
Print @ItemNumber

IF @Type = '1'
BEGIN
--
Print ' '
Print ' Processing Type 1 Pricing...'

--
--Update records in the ES Price file from the Excel spreadsheet
--
Print ' '
Print ' Checking to see if there are any rows to be UPDATED...'
--
UPDATE oeprcfil_sql
SET oeprcfil_sql.minimum_qty_1 = EX.minimum_qty_1,
oeprcfil_sql.prc_or_disc_1 = EX.prc_or_disc_1,
oeprcfil_sql.minimum_qty_2 = EX.minimum_qty_2,
oeprcfil_sql.prc_or_disc_2 = EX.prc_or_disc_2,
oeprcfil_sql.minimum_qty_3 = EX.minimum_qty_3,
oeprcfil_sql.prc_or_disc_3 = EX.prc_or_disc_3,
oeprcfil_sql.minimum_qty_4 = EX.minimum_qty_4,
oeprcfil_sql.prc_or_disc_4 = EX.prc_or_disc_4,
oeprcfil_sql.minimum_qty_5 = EX.minimum_qty_5,
oeprcfil_sql.prc_or_disc_5 = EX.prc_or_disc_5,
oeprcfil_sql.minimum_qty_6 = EX.minimum_qty_6,
oeprcfil_sql.prc_or_disc_6 = EX.prc_or_disc_6,
oeprcfil_sql.minimum_qty_7 = EX.minimum_qty_7,
oeprcfil_sql.prc_or_disc_7 = EX.prc_or_disc_7,
oeprcfil_sql.minimum_qty_8 = EX.minimum_qty_8,
oeprcfil_sql.prc_or_disc_8 = EX.prc_or_disc_8,
oeprcfil_sql.minimum_qty_9 = EX.minimum_qty_9,
oeprcfil_sql.prc_or_disc_9 = EX.prc_or_disc_9,
oeprcfil_sql.minimum_qty_10 = EX.minimum_qty_10,
oeprcfil_sql.prc_or_disc_10 = EX.prc_or_disc_10,
oeprcfil_sql.filler_0004 = 'Changed on ' + CONVERT(VARCHAR(10), GETDATE(), 110)
FROM oeprcfil_sql ES INNER JOIN PriceDataBase...PriceCode1Send$ EX
ON ES.cd_tp = EX.cd_tp
AND ES.curr_cd = EX.curr_cd
AND ES.left(filler_0001,12) = EX.cd_tp_1_cust_no
AND ES.substring(filler_0001,13,15) = EX.cd_tp_1_item_no
AND ES.start_dt = EX.start_dt
AND ES.end_dt = EX.end_dt
WHERE (ES.minimum_qty_1 <> EX.minimum_qty_1)
OR (ES.prc_or_disc_1 <> EX.prc_or_disc_1)
OR (ES.minimum_qty_2 <> EX.minimum_qty_2)
OR (ES.prc_or_disc_2 <> EX.prc_or_disc_2)
OR (ES.minimum_qty_3 <> EX.minimum_qty_3)
OR (ES.prc_or_disc_3 <> EX.prc_or_disc_3)
OR (ES.minimum_qty_4 <> EX.minimum_qty_4)
OR (ES.prc_or_disc_4 <> EX.prc_or_disc_4)
OR (ES.minimum_qty_5 <> EX.minimum_qty_5)
OR (ES.prc_or_disc_5 <> EX.prc_or_disc_5)
OR (ES.minimum_qty_6 <> EX.minimum_qty_6)
OR (ES.prc_or_disc_6 <> EX.prc_or_disc_6)
OR (ES.minimum_qty_7 <> EX.minimum_qty_7)
OR (ES.prc_or_disc_7 <> EX.prc_or_disc_7)
OR (ES.minimum_qty_8 <> EX.minimum_qty_8)
OR (ES.prc_or_disc_8 <> EX.prc_or_disc_8)
OR (ES.minimum_qty_9 <> EX.minimum_qty_9)
OR (ES.prc_or_disc_9 <> EX.prc_or_disc_9)
OR (ES.minimum_qty_10 <> EX.minimum_qty_10)
OR (ES.prc_or_disc_10 <> EX.prc_or_disc_10)


webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-04-18 : 14:29:02
turn
AND ES.left(filler_0001,12) = EX.cd_tp_1_cust_no
into
AND left(ES.filler_0001,12) = EX.cd_tp_1_cust_no


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-04-18 : 14:30:57
filler reminds me: COBOL


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -