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 2000 Forums
 SQL Server Development (2000)
 Group by problem

Author  Topic 

Babli
Yak Posting Veteran

53 Posts

Posted - 2007-04-27 : 03:16:00
Hi,

I have a table with 2 columns namely
Web,UserName

in my Stored Procedure I say

Select fnGetPage(Web) as Page,Count(Web) as Cnt,UserName from table

When Count(Web) is 0 I want an empty result only when it is greater than 0 I want a result.

How can i apply this condition.

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-04-27 : 03:19:09
select page, cnt, username from (
Select fnGetPage(Web) as Page,Count(Web) as Cnt,UserName from table
) as a
where page > 0


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

Babli
Yak Posting Veteran

53 Posts

Posted - 2007-04-27 : 03:21:25
I was wondering if there is a way to put an IF condition while selecting the column.

If not I have go for subquery like how u suggested.


quote:
Originally posted by Peso

select page, cnt, username from (
Select fnGetPage(Web) as Page,Count(Web) as Cnt,UserName from table
) as a
where page > 0


Peter Larsson
Helsingborg, Sweden

Go to Top of Page

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-04-27 : 11:36:50
Then you can remove the WHERE condition in your query. What do you mean by empty result set?



Dinakar Nethi
SQL Server MVP
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-04-27 : 12:06:44
[code]Select fnGetPage(Web) as Page,Count(Web) as Cnt,UserName from table
group by Web, UserName
having Count(Web) > 0[/code]

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page
   

- Advertisement -