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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 need help about procedure

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 ON
go
create 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

)
as
begin
if((select count (*) from employer where username = @username and password = @password) = 1)
begin
set @exist = 1
PRINT 'log in successfully '
end
else set @exist = 0
PRINT 'log in not successfully '
end
--execute
declare @output int
exec employer_login 'employer', 'employer', @output output


--2

create 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)
)
as
begin
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

--execute
exec employer_register 'employer', 'employer','employer','employer' ,'employer' ,
'employer' ,'employer', 'employer' ,'employer' ,'employer' ,'employer' ,'employer'

--3
create proc [dbo].[Candidate_login](

@username nvarchar(50),
@password nvarchar(50),
@exist int output

)
as
begin
if((select count (*) from Candidate where username = @username and password = @password) = 1)
begin
set @exist = 1
PRINT 'log in successfully '
end
else set @exist = 0
PRINT 'log in not successfully '
end
--execute
declare @output int
exec Candidate_login 'Candidate', 'Candidate', @output output


--4
create 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

)
as
begin
DECLARE @invalChars varchar(5),@valid int,@badChar varchar(1),@atPos
int,@periodPos int
SET @valid = 1
SET @invalChars = ' /:,;'
--Check to see if it's blank
IF len(ltrim(rtrim(@email))) = 0
SET @valid = 0
ELSE
--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


--5
create proc [dbo].[Admin_login](

@username nvarchar(50),
@password nvarchar(50),
@exist int output

)
as
begin
if((select count (*) from Admin where username = @username and password = @password) = 1)
begin
set @exist = 1
PRINT 'log in successfully '
end
else set @exist = 0
PRINT 'log in not successfully '
end
--execute
declare @output int
exec 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 MVP
http://visakhm.blogspot.com/

Go to Top of Page

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 22
Must declare the scalar variable "@exist".
Msg 102, Level 15, State 1, Procedure employer_register, Line 30
Incorrect syntax near '='.
Msg 102, Level 15, State 1, Procedure employer_register, Line 38
Incorrect syntax near 'value'.
Msg 102, Level 15, State 1, Procedure employer_register, Line 43
Incorrect 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 specification
1. Employer
i. Log in
Discription The employer who has already account logs in to the website
Input Username
Password
Process Check matching username & password
Log in to the website
Output Inform log in successfully or not
Storage data

ii. Register
Description The employer hasn’t account create account
Input Private / contact employers’ information
Name
Username
Password
Email
Phone …
That employer’’s company/ organization ‘s information
company’s name
company’s fax…

Process Check information validation on the form
Password cannot contain special characters like: $#^%& …
Email format
Phone format …
Username is alph
Check user’s avaibility
Username is not in use.
Insert information into the database
Output Inform registering successfully or not
Storage data Employer’s information.

iii. Manage accout
Discription Employer update his new information, change the password….
Input New information
Process Employer logs in to the website
Enter new information/ new password
Update new information into the database
Output Inform updating new information successfully or not.
Storage data New information.

iv. Retrieve password for existing account
Discription Employer return the forgot password
Input 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 username
Output Inform return the password to the existing employer’s account successfully or not.
Storage data New password.

v. Create favorite candidate list
Discription 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 website
Employer chooses option ‘Add to my list’ in the detailed candidate list
The system adds candidate into the list in the database.
Output Inform adding the candidate into the list successfully or not
Storage data List of candidate

vi. Manage favourite candidate list
Discription Employer manages ( add more/ delete) candidate from the list
Input Choose option ‘Manage my list’
Choose add more or delete
Process Employer logs into the website
Choose 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 database
Output Inform ordering or deleting candidate successfully or not.
Storage data Candidate status if the employer orders candidate

vii. View candidate list
Discription The user has or has not account
Input
Process Click option ‘Candidate list’ at the homepage.
Output Candidate list
Storage data

viii. Search candidate
Discription The user searches the candidate according to some criteria such as career…
Input Search criteria.
Process Input searching criteria
Search/ traverse through the database.
Result in candidate list meeting the criteria.
Output List of candidate who meets the criteria.
Storage data

2. Candidate
i. Log in
Discription Candidate uses his already account to log in to the website
Input Username
Password
Process Check matching username & password
Log into the website
Output Inform logging in to the website successfully or not
Data storage

ii. Register
Discription Candidate has not an account create new one.
Input Username
Password
Personal / contact candidate’s information
Process 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 account
Discription Candidate update his new information, change the password….
Input New information
Process Candidate logs in to the website
Enter new information/ new password
Update new information into the database
Output Inform updating new information successfully or not.
Storage data New information.

iv. Retrieve password for existing account
Discription Candidate asks to return password.
Input Candidate’s email address
Process 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 not
Data storage New password.

v. Post CV
Discription Candidate submits his/ her CV
Input Candidate’s personal information.
Candidate’s contacting information.
Candidate’s related career information
Process Candidate logs in to the website
Enter his/ her related career information such as salary, experience…
Validate information on the form
Insert information into the database
Output Inform posting CV successfully or not
Data storage Candidate’s CV

vi. Manage CV
Discription The candidate manages his/ her account ( update new information/ delete CV)
Input New information
Process Candidate logs in to the website
Enter new information
Update new information into the database
Output Inform update new information successfully or not.
Data storage New / updated information.

vii. Change hiring status
Discription Candidate changes his stt after being hired
Input Click changeStt button
Process Accept request after clicking button
Connect DB
Update candidate STT in DB
Output Inform change stt successfully or not
Data storage New stt

3. Admin
i. Log in
Discription Admin logs in to the website
Input Admin id
Admin username
Process Input admin ID & username
Check the match of id and username
Log in to the website
Output Inform logging in to the website successful or not
Data storage

ii. Search candidate/ employer
Discription Admin searchs candidate according to criteria such as career, age, salary…..
Input Searching criteria
Process Insert Searching criteria
Search database for matching criteria
Result in a list
Output List of candidate matching the searching criteria
Data storage

iii. Deactivate candidate
Discription Admin delete/ deactivate a candidate
Input candidateID
Process Deleting request
Delete that ID from the database
Update the database
Output Inform deleting successfully or not
Data storage

iv. Deactive employer
Discription Admin delete/ deactivate a customer
Input CustomerID
Process Deleting request
Delete customerID from the database
Update database
Output Inform deleting successfully or not
Data storage

v. Update news
Discription Admin add /update news
Input NewsID
Content
Process Input news’content
Update it into database
Output Inform updating successfully or not
Data storage New news

vi. Delete news
Discription Admin deletes old/ out-of-date news
Input News id
Process Delete newsID from database
Update the database
Output Inform deleting successfully or not
Data storage

Hopefully you can help me fix errors and i can finish this project.
Thanks in advance ^^
Warmly




Go to Top of Page

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 address

Process: 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 not

Data storage : New password.
Can anyone help me by posting here a sample T-sql code ? Thanks in advance

Bests
Go to Top of Page
   

- Advertisement -