February 27, 2006 at 4:21 pm
Please read this thread before trying to help me here as it will explain the story behind it.
The problem now is syntax. I've got this all messed up with aliases and stuff that are not quite right..it's a mess and I'm losing my mind. I just need help fixing the syntax ) and aliases here so that the joins all work together based on the d.CustomerNumber that I want to base the join on going through all the subs.
Current Errors:
Msg 170, Level 15, State 1, Line 48
Line 48: Incorrect syntax near ')'.
Msg 170, Level 15, State 1, Line 54
Line 54: Incorrect syntax near ')'.
Msg 170, Level 15, State 1, Line 56
Line 56: Incorrect syntax near ')'.
DECLARE @today DATETIME,
@datefirst datetime,
@Posted money,
@GrossGoal money,
@OldPDCs money,
@NewPDCs money,
@OldCCs money,
@NewCCs money,
@InHouse1 money,
@InHouse2 money,
@Var1 money
SET @today = CONVERT(CHAR(8), GETDATE(), 112) --'Jun 26 2005'
SET @datefirst = @@DATEFIRST
Select @InHouse2 = SUM(inhouse1table.InHouse2)
FROM
(Select SUM (InHouse2Table.InHouse2) * CASE WHEN FeeSchedule = 0 THEN
1
WHEN FeeSchedule = 1 THEN
FeeSchedule / 100
ELSE
FeeSchedule / 100
END AS InHouse2
FROM DC d
INNER JOIN
( Select ddd.CustomerNumber, SUM(ddd.OldCCs) * CASE WHEN FeeSchedule = 0 THEN
1
WHEN FeeSchedule = 1 THEN
(FeeSchedule / 100)
ELSE
(FeeSchedule / 100)
END AS InHouse2
FROM DC ddd
INNER JOIN
(Select dd.CustomerNumber, CC AS OldCCs from DC dd
WHERE dd.EnteredDate BETWEEN DATEADD(DAY, -DATEPART(DAY, @today) + 1, @today) AND DATEADD(DAY, -DATEPART(DAY, @today), DATEADD(MONTH, 1, @today)) AND dd.EnteredDate IS NOT NULL
AND dd.Type = 'CC'
AND ((dd.branch = '00002' and dd.CustomerNumber IN (select CustomerNumber from CustomersAZ where CheckBranch = 1) )
OR (dd.customernumber IN (select CustomerNumber from CustomersAZ where CheckBranch = 0)))
AND dd.pdc_OnHold IS NULL
GROUP BY dd.CustomerNumber,
) as
) as InHouse2Table on d.CustomerNumber = InHouse2Table.CustomerNumber
WHERE d.branch='00002'
AND d.Type = 'In-House'
AND ((d.branch = '00002' and d.CustomerNumber IN (select CustomerNumber from CustomersAZ where CheckBranch = 1))
OR (d.customernumber IN (select CustomerNumber from CustomersAZ where CheckBranch = 0)))
) as inhouse1table
February 27, 2006 at 4:45 pm
Secret of success is to have number of open brackets equal to number of closed brackets.
_____________
Code for TallyGenerator
February 27, 2006 at 7:07 pm
true dat...
March 1, 2006 at 7:37 am
All the syntax errors go away once you remove the comma after
GROUP BY dd.CustomerNumber,
-------------------------------------------------------------------------
Normal chaos will be resumed as soon as possible. :crazy:
March 1, 2006 at 7:40 am
I got some help on this here, therefore this question is resolved:
http://www.experts-exchange.com/Databases/Microsoft_SQL_Server/Q_21755167.html
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply