| |
|
If this is your first visit, be sure to check out the FAQ by clicking the link above.
You may have to register before you can post: click the register link above to proceed.
To start viewing messages, select the forum that you want to visit from the selection below.
|
 |

10-02-03, 05:37
|
|
Registered User
|
|
Join Date: Oct 2003
Location: Miami
Posts: 9
|
|
Quick SQL Homework Help!
|
|
Hi everyone,
I'm new to SQL, and need help with the following problem:
'Create a stored procedure, name employee salary, that will receive two parameters, the employee's id (eid) and the salary increase (incSal). The procedure will then increment the salary by the amount of incSal. The procedure will then print the employee id, name, address and the new salary.'
I don't ask for answers to homework, but today, I'm desparate. I would have asked for help earlier but for my final exam and project for this class. This homework is due later on in the evening.
PLEASE HELP
|
|

10-02-03, 11:25
|
|
Registered User
|
|
Join Date: Sep 2003
Posts: 71
|
|
any attempt from your side
|
|

10-02-03, 12:26
|
|
Registered User
|
|
Join Date: Oct 2003
Location: Miami
Posts: 9
|
|
This is as far as I got
|
|
Quote:
Originally posted by skd
any attempt from your side
|
CREATE PROC INCSAL
STORED PROCEDURE
@EMPLOYEE ID nvarchar(20),
@INCREASE SALARY int
AS
BEGIN
INSERT INTO SALARY (EMP_ ID, INC_SAL)
VALUES (@EMPLOYEE ID,@INCREASE SALARY)
PRINT "EMP_ ID", ;
PRINT "EMP_ NAME" ;
PRINT "ADDRESS";
PRINT "NEW SALARY"
END
STORED PROCEDURE AS
|
|

10-02-03, 13:04
|
|
Registered User
|
|
Join Date: Sep 2003
Posts: 71
|
|
see if this works
---------------------
CREATE OR REPLACE PROCEDURE name_employee_salary (
p_Eid IN NUMBER,
p_IncSal IN NUMBER ) AS
v_Eid employee.employee_id%TYPE;
v_Ename employee.employee_name%TYPE;
v_Eaddress employee.employee_address%TYPE;
v_Esalary employee.employee_salary%TYPE;
BEGIN
UPDATE employee
SET salary=salary + p_IncSal
WHERE employee_id = p_Eid
COMMIT;
SELECT employee_id, employee_name, employee_address, employee_salary
INTO v_Eid, v_Ename, v_Eaddress, v_Esalary
FROM employee
WHERE employee_id=p_Eid;
DBMS_OUTPUT.PUT_LINE ('employee Id : ' || TO_CHAR(v_Eid) );
DBMS_OUTPUT.PUT_LINE ('employee Name : ' || v_Ename );
DBMS_OUTPUT.PUT_LINE ('employee Address : ' || v_Eaddress );
DBMS_OUTPUT.PUT_LINE ('employee New Salary: ' || TO_CHAR(v_Esalary) );
END;
|
|

10-02-03, 14:27
|
|
Registered User
|
|
Join Date: Oct 2003
Location: Miami
Posts: 9
|
|
Thanks a lot!
This is far better than what I had. I'm tweaking it in SQL now. Thanks a bunch.
|
|

10-02-03, 14:42
|
|
Registered User
|
|
Join Date: Oct 2003
Location: Miami
Posts: 9
|
|
My professor didn't show us this:
DBMS_OUTPUT.PUT_LINE ('employee Id : ' || TO_CHAR(v_Eid) );
DBMS_OUTPUT.PUT_LINE ('employee Name : ' || v_Ename );
DBMS_OUTPUT.PUT_LINE ('employee Address : ' || v_Eaddress );
DBMS_OUTPUT.PUT_LINE ('employee New Salary: ' || TO_CHAR
Rather, he wants us to use the PRINT function:
I think this is how it must look:
PRINT ("Employee Name", Name)
PRINT ("Employee Salary", Salary)
PRINT ("Employee ID", EID)
I don't even know if I have the code right, but thanks again.
|
|

10-02-03, 14:53
|
|
Registered User
|
|
Join Date: Sep 2003
Posts: 71
|
|
what sql you are using, i gave you pl/sql verison.
PRINT looks ok to me.
if doesn't works then try
PRINT "Employee ID" + EID
good luck
|
|

10-02-03, 15:04
|
|
Registered User
|
|
Join Date: Oct 2003
Location: Miami
Posts: 9
|
|
I'm using Microsoft SQL Server 2000, but the cd also includes IBM DB2, and MySQL
|
|

10-02-03, 15:18
|
|
Registered User
|
|
Join Date: Sep 2003
Posts: 71
|
|
i am not familiar with sql server but can take a look at errors you getting
|
|

10-02-03, 15:35
|
|
Registered User
|
|
Join Date: Oct 2003
Location: Miami
Posts: 9
|
|
More on the error message
This is the code I have so far:
CREATE PROCEDURE name_employee_salary (
@p_Eid ncvarchar(20),
@p_IncSal
AS
BEGIN
UPDATE employee
SET salary=salary + p_IncSal
WHERE employee_id = p_Eid
COMMIT;
SELECT employee_id, employee_name, employee_salary
FROM employee
WHERE employee_id=p_Eid;
PRINT Employee_name
PRINT Employee_salary
PRINT EID
END
Here's the error message.
Error 156: Incorrect syntax near the keyword 'BEGIN'.
The name 'Employee_name' is not permitted in this context. Only constants, expressions, or variables allowed here. Columns names are not permitted.
The error said the same thing about Employee_salary, and EID
(I won't waste your time writing out the whole thing.)
|
|

10-02-03, 15:48
|
|
Registered User
|
|
Join Date: Sep 2003
Posts: 71
|
|
1) it might not require BEGIN and/or END which aer reserve word used in pl/sql.
2) replace employee_id, employee_name, employee_salary by
actual field of your employee table.
|
|

10-02-03, 15:57
|
|
Registered User
|
|
Join Date: Sep 2003
Posts: 71
|
|
|
|

10-02-03, 18:42
|
|
Registered User
|
|
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,455
|
|
Don't you need to close the parentesis after @p_IncSal?:
CREATE PROCEDURE name_employee_salary (
@p_Eid ncvarchar(20),
@p_IncSal )
....
PS: I neither have any clue about MS SQL...
Good luck.
__________________
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
|
|

10-03-03, 20:07
|
|
Registered User
|
|
Join Date: Oct 2003
Location: Miami
Posts: 9
|
|
Quote:
Originally posted by LKBrwn_DBA
Don't you need to close the parentesis after @p_IncSal?:
CREATE PROCEDURE name_employee_salary (
@p_Eid ncvarchar(20),
@p_IncSal )
....

PS: I neither have any clue about MS SQL...
Good luck.
|
Thanks a lot for your help. I got the work finished on time.
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|