Click here to Skip to main content
15,885,998 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
I have stored procedure as:
SQL
procedure [dbo].[GetIssueBookCount](@stud_id varchar(100),  @book_id varchar(100) )
as
begin

    declare @TotalCount int  = 0;

    select @TotalCount = count(*)  from bookissue where bookid = @book_id and stuid = @stud_id

    set @TotalCount = isnull(@TotalCount,0)

    select @TotalCount as TotalCount;

    select * from library

end


and want to count the no of books available in the library.
The count should vary according to issue and return of books.
If above sp is wrong suggest correct one.
Posted
Comments
Herman<T>.Instance 6-Feb-13 9:36am    
why you do not have tested it yourself?
ZurdoDev 6-Feb-13 9:51am    
What's the question? Just return @TotalCount

Based on just the code you have above... You dont need the select * from Library. You also dont need to have so many sets and selects.

try just
SQL
Select Count(*) As TotalCount FROM bookissue WHERE bookid = @book_id AND stuid = @stud_id



At a guess that will only tell you the number of times that particular book has been issued to that student.

You will most likely need to take into account if the database stores the book being OnSite or Offsite based on a flag on each record, or a new record for each transaction.

If you want to return a count of all books in the library you would need to link some tables, but without more information I cant help.
 
Share this answer
 
What i am getting here

you need to have the count for books available in the library?

SQL
select count(1) from library
where bookid not in (select bookid from bookissue)



There must be some relation in both the tables. What i did here is that i counted the books in the library that does not exists in bookissue table.

I am not sure what columns you have and what conditions to be applied to check but it can help you to find what you are looking for.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900