Solved

Case Statement SQL

Posted on 2011-03-18
3
290 Views
Last Modified: 2012-08-13
I want to check a parameter's length of text with a case statement, what is wrong with this?

CASE @pname WHEN (dbo.length(@pname) > 0) THEN ('arc.contact_name LIKE ''' + @pname + '%'' AND ') ELSE '' END

getting an error about the >
Incorrect syntax near '>'.

Thanks.
0
Comment
Question by:melegant99
  • 2
3 Comments
 
LVL 10

Expert Comment

by:Asim Nazir
ID: 35164403
No need of dbo.length instead use Len((@pname)
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 35164412
this should do:
CASE WHEN (dbo.length(@pname) > 0) THEN ('arc.contact_name LIKE ''' + @pname + '%'' AND ') ELSE '' END

Open in new window

0
 
LVL 10

Expert Comment

by:Asim Nazir
ID: 35164458
You can also go this way:

IF(Len(@pname) > 0)
            select 'arc.contact_name LIKE ''' + @pname + '%'' AND '
      ELSE
            select ''
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question