Solved

Case Statement SQL

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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
separate column 24 20
MySQL ERROR 1045 (28000) 2 40
Change part of a string 2 21
sql query Help 12 17
Creating and Managing Databases with phpMyAdmin in cPanel.
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…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
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…

706 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now