Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Dynamic and complex Sql query(C#+SQL server2000)

Dear Friends,

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.

UpdateEmployee()

FieldName datatYpe

EmpName - string
EmpNo - int
Sex - string
Salary - Float
DoB - datetime
Address - string
Remarks - string
hours - int
AvailableDate -dtatetime

Passed Parameters: EmpNo or EmpName, sex, Salary, DOB, Address,
Remarks,hours, AvailableDate

Please note, this method is overloaded. Although either the EmpNo or
EmpName is required in order to select the Employee record, one or more of
the other variables may be passed.

Return Parameters: ErrorCode

Pseudo Code:

1. Confirm that either the EmpNo or the EmpName exists in the database

2. Confirm that at least one other parameter is passed

3. Confirm that all passed parameters are of the correct data type

4. Update the Employee Table using the Passed Parameters to modify the
fields

Thanks
Joe
[1181 byte] By [Joe] at [2007-11-9 19:34:40]
# 1 Re: Dynamic and complex Sql query(C#+SQL server2000)
This is not entire query but will give an idea

create procedure update_employee

@EmpName VARCHAR(50),
@EmpNo INTEGER,
@Sex VARCHAR(10),
@Salary FLOAT,
@DoB DATETIME,
@Address VARCHAR(200),
@Remarks VARCHAR(1000),
@hours INTEGER,
@AvailableDate DATETIME

AS

BEGIN

if exists ('select EmpNo form employee where EmpNo=' & @EmpNo & ' and EmpName
= ' & @EmpName & ')

BEGIN

if not isnull(@EmpName) and ..... then
UPDATE EMPLOYEE
SET Sex = @Sex,
Salary = @Salary ,
Dob = @DoB ,
Address = @Address ,
Remarks = @Remarks ,
hours = @hours ,
AvailableDate = @AvailableDate
WHERE
EmpName = @EmpName
OR EmpNo = @EmpNo

endif

END

END

"Joe" <rajan_sr99@hotmail.com> wrote:
>
>Dear Friends,
>
>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.
>
>
>UpdateEmployee()
>
>FieldName datatYpe
>
>EmpName - string
>EmpNo - int
>Sex - string
>Salary - Float
>DoB - datetime
>Address - string
>Remarks - string
>hours - int
>AvailableDate -dtatetime
>
>Passed Parameters: EmpNo or EmpName, sex, Salary, DOB, Address,
>Remarks,hours, AvailableDate
>
>Please note, this method is overloaded. Although either the EmpNo or
>EmpName is required in order to select the Employee record, one or more
of
>the other variables may be passed.
>
>Return Parameters: ErrorCode
>
>Pseudo Code:
>
>1. Confirm that either the EmpNo or the EmpName exists in the database
>
>2. Confirm that at least one other parameter is passed
>
>3. Confirm that all passed parameters are of the correct data type
>
>4. Update the Employee Table using the Passed Parameters to modify the
>fields
>
>
>Thanks
>Joe
>
>
dhaya at 2007-11-11 23:50:35 >