Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2005 > SQL Server 2005
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
SQL Server 2005 General discussion of SQL Server *2005* version only.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2005 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 24th, 2011, 10:55 AM
Registered User
Join Date: Jun 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Incorrect Syntax Near "="

I'm trying to make dbo.OrgUnits.OrgPath = "NB" when dbo.OrgUnits.OrgID is null. However I get an error message of 'Incorrect Syntax Near "="' with my code (see below). Can someone please tell me what I'm doing wrong.

SELECT dbo.GLAccounts.GLID, dbo.GLAccounts.BaseID, dbo.OrgUnits.OrgID, dbo.OrgUnits.OrgPath, dbo.OrgUnits.OrgLongName,

When dbo.OrgUnits.OrgID=""
Then dbo.OrgUnits.OrgPath="NB"

dbo.OrgUnits ON dbo.GLAccounts.OrgID = dbo.OrgUnits.OrgID
Reply With Quote
  #2 (permalink)  
Old June 25th, 2011, 09:31 PM
Friend of Wrox
Points: 1,536, Level: 15
Points: 1,536, Level: 15 Points: 1,536, Level: 15 Points: 1,536, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Oct 2006
Location: , MI, USA.
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts

You can't use CASE as if it were an IF in any language. It has to be a part of an "assignment". Give the following a try and see if it does what you want.


 SELECT dbo.GLAccounts.GLID, dbo.GLAccounts.BaseID, dbo.OrgUnits.OrgID, 
        OrgPath = 
            WHEN dbo.OrgUnits.OrgID = ''
            THEN 'NB'
            ELSE dbo.OrgUnits.OrgPath
   FROM dbo.GLAccounts 
   LEFT OUTER JOIN dbo.OrgUnits 
     ON dbo.GLAccounts.OrgID = dbo.OrgUnits.OrgID
--Jeff Moden

Last edited by Jeff Moden; June 25th, 2011 at 09:40 PM..
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
MSXSL gives error message for "for" inside "select" ilyaz XSLT 1 December 9th, 2010 05:02 PM
Difficulties with "web.config" and "ASPNETDB" CFRham BOOK: ASP.NET MVC Website Programming Problem Design Solution ISBN: 9780470410950 2 July 3rd, 2010 10:19 AM
How to theme the "Browse" button of "FileUpload" control? varunbwj BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 2 October 14th, 2009 01:22 AM
Add a CheckBox DataColumn to my DataGridView, Null format: "" or "True" but Error: F ismailc C# 2005 0 September 25th, 2009 04:56 AM
Code not going as planned: "icicle" vs "savedinstancestate" joopthecat BOOK: Professional Android Application Development ISBN: 978-0-470-34471-2 3 May 3rd, 2009 03:09 PM

All times are GMT -4. The time now is 07:02 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.