Solved

return null instead of blank(empty) results

Posted on 2013-01-29
5
460 Views
Last Modified: 2013-01-29
this is just a dummy example.. but if there is no results back for a SELECT query, is there a way to turn the result to NULL instead of empty.
select GETDATE() where 1=2

for the above query, can you display NULL and for

select GETDATE() where 1=1
display the right datetime.?
0
Comment
Question by:25112
  • 2
  • 2
5 Comments
 
LVL 65

Assisted Solution

by:Jim Horn
Jim Horn earned 250 total points
ID: 38831289
Not real sure where you're going with this, but I'll play along...

SELECT CASE WHEN Something = SomeValue THEN GETDATE() ELSE NULL END as column_name
0
 
LVL 15

Accepted Solution

by:
santhimurthyd earned 250 total points
ID: 38831309
With No recordsselect AR.date
from (select 1 as defaultRec) DR
left join (
     select isnull(GETDATE(),'') date where 1=2 -- original query
)AR on 1=1

with valid condition
select AR.date
from (select 1 as defaultRec) DR
left join (
     select isnull(GETDATE(),'') date where 1=1 -- original query
)AR on 1=1

Are you looking out the above results
0
 
LVL 5

Author Comment

by:25112
ID: 38831478
this will do... v efficient.. thx
0
 
LVL 5

Author Comment

by:25112
ID: 38831509
what will be best way to implement your idea in this:
 (SELECT AVG((100*[ItemsPassed])/[ItemList]) AS GoodRate FROM tblRates WHERE CatID = 1030 GROUP BY CatID) Item5

(this is a implied table) in a series of cross join.

like this
 (SELECT AVG((100*[ItemsPassed])/[ItemList]) AS GoodRate FROM tblRates WHERE CatID = 1030 GROUP BY CatID) Item3
JOIN
 (SELECT AVG((100*[ItemsPassed])/[ItemList]) AS GoodRate FROM tblRates WHERE CatID = 1032 GROUP BY CatID) Item4
JOIN
 (SELECT AVG((100*[ItemsPassed])/[ItemList]) AS GoodRate FROM tblRates WHERE CatID = 1037 GROUP BY CatID) Item5

etc

only for Item5, it returns nothing.
0
 
LVL 65

Expert Comment

by:Jim Horn
ID: 38831569
Thanks for the split.  Good luck with your project.  -Jim
0

Featured Post

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

705 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