SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 slq syntax err
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

emmim44
Yak Posting Veteran

65 Posts

Posted - 07/13/2012 :  03:54:57  Show Profile  Reply with Quote
I am getting a syntax err. Can anyone point it out? @username is an optional variable.

Msg 156, Level 15, State 1, Line 64
Incorrect syntax near the keyword 'case'.

where ---OperationType = 'U'
dwo.operationDate between convert(varchar,@sDate,1) and convert(varchar,@eDate,1)
(case when @userName <>'' then And p.CentralAccount = @userName else end)

And dwo.ObjectKey = ( select XObjectKey

sql-programmers
Posting Yak Master

USA
189 Posts

Posted - 07/13/2012 :  04:20:26  Show Profile  Reply with Quote
I think Logical operators missed

where ---OperationType = 'U'
dwo.operationDate between convert(varchar,@sDate,1) and convert(varchar,@eDate,1)

(AND / OR)

(case when @userName <>'' then And p.CentralAccount = @userName else end)


SQL Server Programmers and Consultants
http://www.sql-programmers.com/
Go to Top of Page

emmim44
Yak Posting Veteran

65 Posts

Posted - 07/13/2012 :  04:26:04  Show Profile  Reply with Quote
quote:
Originally posted by sql-programmers

I think Logical operators missed

where ---OperationType = 'U'
dwo.operationDate between convert(varchar,@sDate,1) and convert(varchar,@eDate,1)

(AND / OR)

(case when @userName <>'' then And p.CentralAccount = @userName else end)


SQL Server Programmers and Consultants
http://www.sql-programmers.com/


I dont think so... I am already including "And p.CentralAccount = @userName "
Go to Top of Page

emmim44
Yak Posting Veteran

65 Posts

Posted - 07/13/2012 :  04:38:43  Show Profile  Reply with Quote
it is solved...Solution is:
And p.CentralAccount =
(case when @userName <>'' then @userName else p.CentralAccount end)

Thank you all.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.27 seconds. Powered By: Snitz Forums 2000