Solved

How to set MSSQL result to text

Posted on 2010-08-13
5
641 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

744 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

15 Experts available now in Live!

Get 1:1 Help Now