2013-04-16 57 views
-1

救我要選擇僱員和9.5%增加他/她的工資,並保存在數據庫中查詢,增加工資和數據庫

查詢作爲followed..I使用了兩個相關的表Employee_Tbl和Job_Tbl變化在SQL Server 2008

SELECT Employee_Tbl.EmployeeID, 
     Employee_Tbl.Salary,(Employee_Tbl.Salary*5/100)+Employee_Tbl.Salary as  
     SalaryIncreaseByFivePercent 
FROM Employee_Tbl INNER JOIN 
         Job_Tbl ON Employee_Tbl.JobTitle = Job_Tbl.JobTitle 

我面臨的問題,使用相同的查詢保存在數據庫中的其他列SalaryIncreaseByFivePercent。 任何人都可以告訴?

+0

? –

+0

我想在查詢中創建一個新列 –

+0

另外,百分比是多少。在問題的開頭,你說9.5%,但在其他地方你說5%。 –

回答

0

你想使用和UPDATE聲明在這裏。類似以下的東西將做的伎倆

UPDATE Emplotee_Tbl 
SET Employee_Tbl.Salary = (Employee_Tbl.Salary*5/100) + Employee_Tbl.Salary 
FROM Employee_Tbl AS et 
    INNER JOIN Job_Tbl AS jt 
     ON et.JobTitle = jt.JobTitle 
WHERE Employee_Tbl.EmployeeLastName = "Burns"; 
GO 

我希望這可以幫助。


編輯。要創建一個名爲SalaryIncreaseByFivePercent新列並插入更新的薪水在那裏,你可以只創建一個使用

ALTER TABLE table_name 
ADD column_name datatype; 
GO 
0

我不就可以在選擇查詢,添加一列

首先添加一個新列新的列存儲浮動數據類型的增加工資increasedSalary

ALTER TABLE Employee_Tbl 
ADD increasedSalary float 

然後更新表

UPDATE Emplotee_Tbl 
SET increasedSalary = (Employee_Tbl.Salary*5/100) + Employee_Tbl.Salary 
FROM Employee_Tbl t 
    INNER JOIN Job_Tbl j 
ON t.JobTitle = j.JobTitle 
要`SalaryIncreaseByFivePercent`保存到`Salary`列或想在Employee_Tbl表中的新列,並保存工資增加有