Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 select query when result is nothing

Author  Topic 

cplusplus
Aged Yak Warrior

567 Posts

Posted - 2010-04-15 : 19:28:19
I want to use the following select:

select isnull(rtrim(FilePath),'\') from tab_doc_repository where docid=0

when i pass zero the result is nothing when it is nothing i want to

show just this '\', is it possible?

Thanks for the helpful info.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-04-15 : 19:32:19
In order to know how many rows are returned, you'd have to check @@ROWCOUNT after the query runs. So the below would appear in a different result set.

IF @@ROWCOUNT = 0
SELECT '\'

Perhaps someone else has a better solution though.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

cplusplus
Aged Yak Warrior

567 Posts

Posted - 2010-04-15 : 20:46:03
Hello Tara,

It is always one row, it is either one row of info or nothing.

when it is nothing i want to show just the '\' backslash.

Thank you.
Go to Top of Page

nathans
Aged Yak Warrior

938 Posts

Posted - 2010-04-15 : 21:38:57
If its a single row, then how about:

select top 1 *
from ( select FilePath [FilePath],
0 [r]
from tab_doc_repository
where docid = 0
union all
select '/',
1
)d
order
by [r] asc
Go to Top of Page
   

- Advertisement -