Unanswered: SQL Server Constraint20000------Please help
How do write the below dynamic update Query? I am new to this SQL Query.Its
very very urgent requirements.
If anyone knows please help me the below SQL query.
I would appreciate any help.
EmpName - string
EmpNo - int
Sex - string
Salary - Float
DoB - datetime
Address - string
Remarks - string
hours - int
create procedure dbo.UpdateEmployee (
@EmpName varchar(255) = null,
@EmpNo int = null,
if not exists (
select * from dbo.EmployeeMaster where (EmpNo = @EmpNo or EmpName = @EmpName) begin
raiserror ('Invalid Employee specified!', 15, 1)
end else begin
if @EmpNo is null
select @EmpNo = EmpNo from EmployeeMaster where EmpName = @EmpName
-- At this point we KNOW that @EmpNo has a value, - whether it was passed or we retrieved it ourselves
-- Go ahead and check the validity of the rest of the variables
-- Perform the UPDATE using EmpNo = @EmpNo, because most likely you have a UNIQUE constraint or index on it or a CLUSTERED index, - thus the query will be faster.