Solved

Case Statement SQL

Posted on 2011-03-18
3
291 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 143

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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Suggested Solutions

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

791 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