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.
Author |
Topic |
chrvik
Starting Member
7 Posts |
Posted - 2012-11-16 : 05:07:33
|
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
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2012-11-16 : 06:19:23
|
The SP is called with the parameter and it returns the count.The SP would be something likecreate proc s_CountUserEntries@UserID int ,@count in outasselect @count = count(*)from ForumPostswhere UserID = @UserIDgothen call it with declare @Count intdeclare @UserID intselect @UserID = MyUserID ...exec s_CountUserEntries @UserID = @UserID, @Count = @Count int outselect @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. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-11-16 : 22:32:29
|
quote: Originally posted by nigelrivett The SP is called with the parameter and it returns the count.The SP would be something likecreate proc s_CountUserEntries@UserID int ,@count int outasselect @count = count(*)from ForumPostswhere UserID = @UserIDgothen call it with declare @Count intdeclare @UserID intselect @UserID = MyUserID ...exec s_CountUserEntries @UserID = @UserID, @Count = @Count int outselect @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 MVPhttp://visakhm.blogspot.com/ |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
chrvik
Starting Member
7 Posts |
Posted - 2012-11-17 : 10:39:12
|
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. |
|
|
|
|
|