Solved

Case Statement SQL

Posted on 2011-03-18
3
294 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Display SQL maintenance plan SQL Code 3 44
What is GIS method of Geometry data type? 6 28
Replace statements HTML with HTML IF 8 54
SQL query 45 31
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how the fundamental information of how to create a table.

738 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