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)
 Help creating query

Author  Topic 

theonlylawislove
Starting Member

7 Posts

Posted - 2008-04-01 : 19:34:52
[code]SELECT Name, TagID,
(SELECT COUNT(TagID) AS Expr1
FROM dbo.mw_PagesTagMap
WHERE (TagID = tag.TagID)) AS TagWeight
FROM dbo.mw_Tags AS tag[/code]




This query works exactly how I want it to.
I would like to modify this to NOT return any column that has a TagWeight of 0

[code]SELECT Name, TagID,
(SELECT COUNT(TagID) AS Expr1
FROM dbo.mw_PagesTagMap
WHERE (TagID = tag.TagID)) AS TagWeight
FROM dbo.mw_Tags AS tag
WHERE (TagWeight <> 0)[/code]
I thought this would do it but I'm getting an error "invalied column TagWeight".
How would I get this to work?

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-04-01 : 19:51:40
SELECT Name, TagID,
(SELECT COUNT(TagID) AS Expr1
FROM dbo.mw_PagesTagMap
WHERE (TagID = tag.TagID)
Having count(TagID)>=1) AS TagWeight
FROM dbo.mw_Tags AS tag
Go to Top of Page

theonlylawislove
Starting Member

7 Posts

Posted - 2008-04-01 : 23:37:43
quote:
Originally posted by sodeep

SELECT Name, TagID,
(SELECT COUNT(TagID) AS Expr1
FROM dbo.mw_PagesTagMap
WHERE (TagID = tag.TagID)
Having count(TagID)>=1) AS TagWeight
FROM dbo.mw_Tags AS tag



note quite...

This query still returns that Tag that is used more than once, this time with a null value.

I'm looking to ONLY SELECT THE TAGS THAT ARE USED.

Thanks!
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-04-01 : 23:54:29
SELECT Name, TagID,
(SELECT COUNT(TagID) AS Expr1
FROM dbo.mw_PagesTagMap
WHERE (TagID = tag.TagID)and tag.TagID is not null
Having count(TagID)>=1) AS TagWeight
FROM dbo.mw_Tags AS tag
Go to Top of Page
   

- Advertisement -