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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 slq syntax err

Author  Topic 

emmim44
Yak Posting Veteran

65 Posts

Posted - 2012-07-13 : 03:54:57
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

190 Posts

Posted - 2012-07-13 : 04:20:26
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 - 2012-07-13 : 04:26:04
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 - 2012-07-13 : 04:38:43
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
   

- Advertisement -