Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with CASE & COALESCE

Status
Not open for further replies.

katbear

Programmer
Mar 14, 2007
270
US
Hi,

Getting errors on:

Code:
SELECT 
  ab.ClosingBalance,
  CASE
    WHEN v1.Broker = 'Smith Barney'
      THEN NULL
    ELSE
      COALESCE(v1.Balance1, v2.Balance2) AS BegBalance
   END
FROM myView1 v1
LEFT OUTER JOIN myView2 v2
ON  v1.Broker = v2.Broker

The error is:

Msg 156, Level 15, State 1, Procedure myProc, Line 44
Incorrect syntax near the keyword 'AS'.

Doesn't seem to like the "AS", but I need to do this.

Please help.

Thanks
 
Hi,

It's not that it doesn't like the word "AS". Try putting single quotes around BegBalance like this 'BegBalance'.

GOOD LUCK!
 
Name of the field must be after the END of the CASE
Code:
SELECT
  ab.ClosingBalance,
  CASE
    WHEN v1.Broker = 'Smith Barney'
      THEN NULL
    ELSE
      COALESCE(v1.Balance1, v2.Balance2)
   END [COLOR=red]AS BegBalance[/color]
FROM myView1 v1
LEFT OUTER JOIN myView2 v2
ON  v1.Broker = v2.Broker

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
MVP VFP
 
Thanks, putting it after the END worked
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top