Solved

How to set MSSQL result to text

Posted on 2010-08-13
5
667 Views
Last Modified: 2012-05-10
I have a few queries that count the amount of documents that are run, and it also displays the amount of seconds since the last document was processed. What I would like to do, is when there are no more documents to process, instead of displaying a 0, I would like to display a text indicating that there are no more pending documents. Here's what I have:

COUNT(CASE WHEN success IS NULL AND processed_dts IS NULL THEN 'No documents to process' END)

If I take out the COUNT, I will get an error because I am not using an aggregate function.

Thanks...
0
Comment
Question by:horalia
5 Comments
 
LVL 16

Expert Comment

by:vdr1620
ID: 33432597
Try this..
CASE WHEN COUNT(success) IS NULL AND COUNT(processed_dts) IS NULL THEN 'No documents to process' END

I would be better to post your complete code with some sample data
0
 
LVL 8

Expert Comment

by:mustaccio
ID: 33432618
Try using MAX() instead of COUNT()
0
 
LVL 3

Accepted Solution

by:
man2002ua earned 500 total points
ID: 33436218
Hmm
CASE  WHEN SUM(CASE WHEN success IS NULL AND processed_dts IS NULL THEN 0 ELSE 1 END) = 0
   THEN  'No documents to process'
ELSE
  CAST(SUM(CASE WHEN success IS NULL AND processed_dts IS NULL THEN 0 ELSE 1 END) AS VARCHAR)
END
0
 

Author Comment

by:horalia
ID: 33599600
Thanks for all your comments experts, I was on vacation the last two weeks, I'm currently trying out man2002ua suggestion, will continue updating this question... Thanks!
0
 

Author Closing Comment

by:horalia
ID: 33643660
Worked like a charm! Thanks! Sorry for the delay in closing this question...
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

This article will describe one method to parse a delimited string into a table of data.   Why would I do that you ask?  Let's say that you need to pass multiple parameters into a stored procedure to search for.  For our sake, we'll say that we wa…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

821 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