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 |
phoebe90
Starting Member
3 Posts |
Posted - 2011-01-04 : 12:02:42
|
Dear friends !I have done a small project and i had some difficulties that i need your help to fix it. My task in this project is building the database and running the queries statement to test all use cases: customers/ candidate/ admin. And every use cases’ query statement must be written in stored procedure manner. Below is my code with many error,please help me check and fix it. Thanks in advance  SET NOCOUNT ONgocreate database human_resource_management;use human_resource_management;create table CV( cvID int, candidateID int, can_img image, working_area nvarchar, working_place nvarchar, position nvarchar, workingTime nvarchar, salary nvarchar, degree nvarchar, chung_chi nvarchar, university nvarchar, uni_address nvarchar, falcuty nvarchar, graduated nvarchar, used_job nvarchar, num_experience nvarchar, description nvarchar, submitTime nvarchar, ngon_ngu nvarchar );create table candidate( candidateID int, fullname nvarchar, sex nvarchar, DOB nvarchar, marriage_stt nvarchar, address nvarchar, distrist nvarchar, city nvarchar, phone int, email nvarchar, username nvarchar, password nvarchar, candidateStatus nvarchar, blocked nvarchar, time_chstt nvarchar );create table employer( employerID int, em_img image, fullname nvarchar, sex nvarchar, username nvarchar, password nvarchar, companyName nvarchar, companyEmail nvarchar, companyAddress nvarchar, company_fax nvarchar, companyPhone nvarchar, companyField nvarchar, company_Description nvarchar, website nvarchar, timeRegister nvarchar, lastVisit nvarchar, blocked nvarchar );create table quantri( ID int, fullname nvarchar, username nvarchar, password nvarchar, bac nvarchar );create table FavouriteCandidate( employerID int, candidateID int, addedTime nvarchar );create table news( newsID int, newsTitle nvarchar, newsContent nvarchar, author nvarchar, timepost nvarchar, summary nvarchar );drop procedure [dbo].[employer_login]create proc [dbo].[employer_login]( @username nvarchar(50), @password nvarchar(50), @exist int output)asbegin if((select count (*) from employer where username = @username and password = @password) = 1)begin set @exist = 1PRINT 'log in successfully 'endelse set @exist = 0PRINT 'log in not successfully 'end --executedeclare @output intexec employer_login 'employer', 'employer', @output output--2create proc [dbo].[employer_register]( @name nvarchar(50), @username nvarchar(50), @password nvarchar(50), @email nvarchar(50), @phone nvarchar(50), @companyName nvarchar(50), @companyEmail nvarchar(50), @companyAddress nvarchar(50), @company_fax nvarchar(50), @companyPhone nvarchar(50), @companyField nvarchar(50), @company_Description nvarchar(50))asbegin if((select count (*) from employer where username = @username)=1) begin PRINT 'This account was used! Please choose another one!' END else set @exist = 0 BEGIN PRINT 'You can use this account!' --- kiem tra email hop. le. if(@email IS NOT NULL) set @email= ( CHARINDEX(' ',LTRIM(RTRIM([Email]))) = 0 -- No embedded spaces AND LEFT(LTRIM([Email]),1) <> '@' -- '@' can't be the first character of an email address AND RIGHT(RTRIM([Email]),1) <> '.' -- '.' can't be the last character of an email address AND LEN(LTRIM(RTRIM([Email]))) - LEN(REPLACE(LTRIM(RTRIM([Email])),'@','')) = 1 -- Only one '@' sign is allowed AND CHARINDEX('.',REVERSE(LTRIM(RTRIM([Email])))) >= 3 AND (CHARINDEX('.@',[Email]) = 0 AND CHARINDEX('..',[Email]) = 0) -- can't have patterns like '.@' and '..' ) print 'acceptable' insert into employer value() end--executeexec employer_register 'employer', 'employer','employer','employer' ,'employer' ,'employer' ,'employer', 'employer' ,'employer' ,'employer' ,'employer' ,'employer'--3create proc [dbo].[Candidate_login]( @username nvarchar(50), @password nvarchar(50), @exist int output)asbegin if((select count (*) from Candidate where username = @username and password = @password) = 1)begin set @exist = 1PRINT 'log in successfully 'endelse set @exist = 0PRINT 'log in not successfully 'end --executedeclare @output intexec Candidate_login 'Candidate', 'Candidate', @output output--4create proc [dbo].[Candidate_register]( @name nvarchar(50), @username nvarchar(50), @password nvarchar(50), @email nvarchar(50), @phone nvarchar(50), @companyName nvarchar(50), @companyEmail nvarchar(50), @companyAddress nvarchar(50), @company_fax nvarchar(50), @companyPhone nvarchar(50), @companyField nvarchar(50), @company_Description nvarchar(50), @exist int output)asbegin DECLARE @invalChars varchar(5),@valid int,@badChar varchar(1),@atPosint,@periodPos intSET @valid = 1SET @invalChars = ' /:,;'--Check to see if it's blankIF len(ltrim(rtrim(@email))) = 0 SET @valid = 0ELSE --Loop invalid characters to see if it exists in email WHILE len(@invalChars) > 0 BEGIN SET @badChar = substring(@invalChars,1,1) IF(charindex(@badChar,@email) > 0) --If invalid character was found, return 0 to invalidate SET @valid = 0 SET @invalChars = replace(@invalChars,@badChar,'') END --Check to see if "@" exists. SET @atPos = charindex('@',@email,1) IF @atPos = 0 SET @valid = 0 --Check to see if extra "@" exists after 1st "@". IF charindex('@',@email,@atPos+1) > 0 SET @valid = 0 SET @periodPos = charindex('.',@email,@atPos) IF @periodPos = 0 SET @valid = 0 IF (@periodPos+3) > len(@email) SET @valid = 0 RETURN (@valid)END--5create proc [dbo].[Admin_login]( @username nvarchar(50), @password nvarchar(50), @exist int output)asbegin if((select count (*) from Admin where username = @username and password = @password) = 1)begin set @exist = 1PRINT 'log in successfully 'endelse set @exist = 0PRINT 'log in not successfully 'end --executedeclare @output intexec Admin_login 'Candidate', 'Candidate', @output output Best regards !Phoebe |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-01-04 : 13:06:59
|
you mean you want somebody to try executing this code and fix all errors for you? it may be better to post which specific error you want help with.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
phoebe90
Starting Member
3 Posts |
Posted - 2011-01-04 : 13:51:32
|
Dear you!I have encountered with many syntax errors in the proc [dbo].[employer_register] (i want to check the email format )i posted above such as : Msg 137, Level 15, State 1, Procedure employer_register, Line 22Must declare the scalar variable "@exist".Msg 102, Level 15, State 1, Procedure employer_register, Line 30Incorrect syntax near '='.Msg 102, Level 15, State 1, Procedure employer_register, Line 38Incorrect syntax near 'value'.Msg 102, Level 15, State 1, Procedure employer_register, Line 43Incorrect syntax near 'employer'.Well there is 2 proc about email format, one runs but one has many errors and i want to fix it. Also, please have a look at the Use case specification that i must follow and use procedure to test these use cases(i post below) and help me with the session : Retrieve password for existing account.II. Use case specification1. Employeri. Log inDiscription The employer who has already account logs in to the websiteInput UsernamePassword Process Check matching username & passwordLog in to the websiteOutput Inform log in successfully or notStorage data ii. RegisterDescription The employer hasn’t account create accountInput Private / contact employers’ informationNameUsernamePasswordEmailPhone …That employer’’s company/ organization ‘s informationcompany’s namecompany’s fax…Process Check information validation on the formPassword cannot contain special characters like: $#^%& …Email formatPhone format …Username is alphCheck user’s avaibilityUsername is not in use.Insert information into the databaseOutput Inform registering successfully or notStorage data Employer’s information.iii. Manage accoutDiscription Employer update his new information, change the password….Input New informationProcess Employer logs in to the websiteEnter new information/ new passwordUpdate new information into the databaseOutput Inform updating new information successfully or not.Storage data New information.iv. Retrieve password for existing accountDiscription Employer return the forgot passwordInput Email address Process Check existence of email in the database -if email does not exist, the system will be inform “ this email does not exist!” - if email exist, the system will send/ create new password for this existing usernameOutput Inform return the password to the existing employer’s account successfully or not.Storage data New password.v. Create favorite candidate listDiscription Employer adds candidate into the favouriteCandidate list, so in the next visit he can order that candidate for quick.Input Choose option ‘Add to my list’Process Employer logs into the websiteEmployer chooses option ‘Add to my list’ in the detailed candidate listThe system adds candidate into the list in the database. Output Inform adding the candidate into the list successfully or notStorage data List of candidatevi. Manage favourite candidate listDiscription Employer manages ( add more/ delete) candidate from the listInput Choose option ‘Manage my list’Choose add more or deleteProcess Employer logs into the websiteChoose option ‘Qu?n lý Danh sách c?a tôi’- choose option ‘add more ’ ? ‘add more’ use case-choose option ‘delete’ -> the system deletes that candidate from the databaseOutput Inform ordering or deleting candidate successfully or not. Storage data Candidate status if the employer orders candidatevii. View candidate listDiscription The user has or has not accountInput Process Click option ‘Candidate list’ at the homepage.Output Candidate listStorage data viii. Search candidateDiscription The user searches the candidate according to some criteria such as career…Input Search criteria.Process Input searching criteriaSearch/ traverse through the database.Result in candidate list meeting the criteria.Output List of candidate who meets the criteria.Storage data 2. Candidatei. Log inDiscription Candidate uses his already account to log in to the websiteInput UsernamePasswordProcess Check matching username & passwordLog into the websiteOutput Inform logging in to the website successfully or notData storage ii. RegisterDiscription Candidate has not an account create new one.Input UsernamePassword Personal / contact candidate’s informationProcess Check information validation on the form.Check username avaibility.Insert information into the database.Output Inform registering successfully or not.Data storage Candidate’s information.iii. Manage accountDiscription Candidate update his new information, change the password….Input New informationProcess Candidate logs in to the websiteEnter new information/ new passwordUpdate new information into the databaseOutput Inform updating new information successfully or not.Storage data New information.iv. Retrieve password for existing accountDiscription Candidate asks to return password.Input Candidate’s email address Process Check existence of email in the databaseIf email exists in the DB, send new passIf not, inform “This email does not exist!”Output Inform returning new password for the existing account successfully or notData storage New password.v. Post CVDiscription Candidate submits his/ her CV Input Candidate’s personal information.Candidate’s contacting information.Candidate’s related career informationProcess Candidate logs in to the websiteEnter his/ her related career information such as salary, experience…Validate information on the form Insert information into the databaseOutput Inform posting CV successfully or not Data storage Candidate’s CVvi. Manage CVDiscription The candidate manages his/ her account ( update new information/ delete CV)Input New informationProcess Candidate logs in to the websiteEnter new informationUpdate new information into the databaseOutput Inform update new information successfully or not. Data storage New / updated information.vii. Change hiring statusDiscription Candidate changes his stt after being hiredInput Click changeStt buttonProcess Accept request after clicking buttonConnect DBUpdate candidate STT in DBOutput Inform change stt successfully or notData storage New stt3. Admini. Log inDiscription Admin logs in to the website Input Admin idAdmin usernameProcess Input admin ID & usernameCheck the match of id and usernameLog in to the websiteOutput Inform logging in to the website successful or notData storage ii. Search candidate/ employerDiscription Admin searchs candidate according to criteria such as career, age, salary…..Input Searching criteria Process Insert Searching criteria Search database for matching criteriaResult in a listOutput List of candidate matching the searching criteriaData storage iii. Deactivate candidateDiscription Admin delete/ deactivate a candidateInput candidateIDProcess Deleting requestDelete that ID from the databaseUpdate the databaseOutput Inform deleting successfully or notData storage iv. Deactive employerDiscription Admin delete/ deactivate a customerInput CustomerIDProcess Deleting requestDelete customerID from the databaseUpdate databaseOutput Inform deleting successfully or notData storage v. Update newsDiscription Admin add /update newsInput NewsIDContent Process Input news’contentUpdate it into databaseOutput Inform updating successfully or notData storage New newsvi. Delete newsDiscription Admin deletes old/ out-of-date newsInput News idProcess Delete newsID from databaseUpdate the databaseOutput Inform deleting successfully or notData storage Hopefully you can help me fix errors and i can finish this project.Thanks in advance ^^Warmly |
 |
|
phoebe90
Starting Member
3 Posts |
Posted - 2011-01-05 : 10:25:56
|
Dear friends !Well, i tried and fixed my code but i still have problems with part : Retrieve password for existing account.Discription :Candidate asks to return password.Input : Candidate’s email addressProcess: Check existence of email in the database If email exists in the DB, send new pass If not, inform “This email does not exist!”Output: Inform returning new password for the existing account successfully or notData storage : New password.Can anyone help me by posting here a sample T-sql code ? Thanks in advanceBests |
 |
|
|
|
|
|
|