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
 General SQL Server Forums
 New to SQL Server Programming
 Stored procedure with count statment Error

Author  Topic 

ahmed123
Starting Member

2 Posts

Posted - 2010-01-02 : 09:54:17
Hello all members
I am biginner and need you help.
I have two tables one named BDATA i whitch i am storeing business information and other tabel as Reviews to store the reviews on Businesses.
Now i want to make a stored procedure that an argumet @ReviewCount
and return me Data from BDate table with count of reviews that has more reviews than the @ReviewCount
I am trying to create a stored procedure but getting the error "Invalid colum name ReviewCount"
This is teh stored procedure

CREATE PROCEDURE [dbo].[SB]

(
@ReviewCount int
)

AS
SELECT BDATA.data_id,(SELECT COUNT(*) AS Expr2
FROM Reviews
WHERE (Reviews.ResID = BData.data_id))
AS ReviewCount
FROM BDATA
Where
(ReviewCount>@ReviewCount) OR (@ReviewCount =0)

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-01-02 : 10:05:55
[code]CREATE PROCEDURE [dbo].[SB]

(
@ReviewCount int
)

AS
SELECT BDATA.data_id,r.Reviews
FROM BDATA
JOIN (SELECT ResID,COUNT(Reviews.PK) AS Reviews
FROM Reviews
GROUP BY ResID) r
ON r.ResID = BData.data_id
WHERE r.Reviews>@ReviewCount
OR @ReviewCount =0[/code]
Go to Top of Page

ahmed123
Starting Member

2 Posts

Posted - 2010-01-04 : 00:29:43
Thanks visakh
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-01-04 : 01:35:11
welcome
Go to Top of Page
   

- Advertisement -