SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Add user session
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

chrvik
Starting Member

7 Posts

Posted - 11/16/2012 :  05:07:33  Show Profile  Reply with Quote
How do I add a user session in a SQL statement?

Using Dreamweaver/Vb/Access.
Wanting to count how many times a user has made an entry to a forum and since the page is dynamic I have to do the count based on user session (id)

"sunitabeck" suggested I created a stored procedure with a parameter (such as @UserId) and then call that stored procedure from the client code, passing in the userId of the user who is viewing the page.

Only problem is I'm quite new to SQL. Thinking I have to call it in the WHERE clause, just not sure how.

nigelrivett
Flowing Fount of Yak Knowledge

United Kingdom
3355 Posts

Posted - 11/16/2012 :  06:19:23  Show Profile  Visit nigelrivett's Homepage  Reply with Quote
The SP is called with the parameter and it returns the count.

The SP would be something like
create proc s_CountUserEntries
@UserID int ,
@count in out
as
select @count = count(*)
from ForumPosts
where UserID = @UserID
go

then call it with

declare @Count int
declare @UserID int
select @UserID = MyUserID ...
exec s_CountUserEntries @UserID = @UserID, @Count = @Count int out
select @Count


==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52249 Posts

Posted - 11/16/2012 :  22:32:29  Show Profile  Reply with Quote
quote:
Originally posted by nigelrivett

The SP is called with the parameter and it returns the count.

The SP would be something like
create proc s_CountUserEntries
@UserID int ,
@count int out
as
select @count = count(*)
from ForumPosts
where UserID = @UserID
go

then call it with

declare @Count int
declare @UserID int
select @UserID = MyUserID ...
exec s_CountUserEntries @UserID = @UserID, @Count = @Count int out
select @Count


==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.


small typo fixed

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52249 Posts

Posted - 11/16/2012 :  22:33:48  Show Profile  Reply with Quote
also see various ways of returning values from procedures here

http://www.sqlteam.com/article/stored-procedures-returning-data

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

chrvik
Starting Member

7 Posts

Posted - 11/17/2012 :  10:39:12  Show Profile  Reply with Quote
Thank you both for responding!

I'm trying to twist my head around this but I can't get it to work.
Thought it might be easier. Dreamweaver is throwing all kinds of errors and that is probably because I've never created a SP before and used it later in a recordset.

What is the absolute easiest way to do this?
Have to start at the bottom on build my way up in order to understand.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000