9/23/09

Survey and user ID's

As you remember, after user had chose answers he will press the submit buttom
And his answers will be stored in DataBase.
For being able to store the answers
we need user's 'id' to be stored along with each of his answers.
This code can get us that we need:
string strUserID = Membership.GetUser(User.Identity.Name).ProviderUserKey.ToString();



Getting Relevant Survey Id
Same user cannot do the same survey twice, therefore we need to display him one of the surveys he didnt answer yet.
Here is stored procedure i wrote for this task:
ALTER PROCEDURE dbo.getRelevantSurveys

@user_id nvarchar(256)

AS
SELECT  [survey_id]
FROM    [surveys]
WHERE   [IsPublished]=1 AND
(survey_id NOT IN
(SELECT surveys_1.survey_id
FROM  users_answers INNER JOIN questions ON
[users_answers].[question_id] = [questions].[questionID]
INNER JOIN

surveys AS surveys_1 ON
surveys_1.[survey_id]= questions.surv_id
WHERE      (users_answers.user_id = @user_id)
GROUP BY surveys_1.survey_id))
      RETURN

No comments:

Post a Comment

Getting started with docker

It is very simple to get started usig docker. All you need to do-is download the docker desktop for your system Once you get docker syste...