Reputation:
i have a table "employers"
Employerid int
InsuranceNumber varchar(10)
Ministry nvarchar(100)
Adress nvarchar(250)
PostalCode varchar(50)
Phone varchar(14)
Mobile varchar(14)
Email nvarchar(60)
UserName nvarchar(50)
Password nvarchar(50)
ContactPerson nvarchar(250)
EntryDate datetime
LastUpdateDate datetime
IsDeleted bit
Active bit
and i have created how to insert data using insert stored proc
Create procedure dbo.Employers_Insert
@InsuranceNumber nvarchar(10),
@Ministry nvarchar(100),
@Adress nvarchar(250),
@PostalCode varchar(50),
@Phone varchar(14),
@Mobile varchar(14),
@Email nvarchar(60),
@UserName nvarchar(50),
@Password nvarchar(50),
@ContactPerson nvarchar(250),
@EntryDate datetime,
@LastUpdateDate datetime,
@IsDeleted bit,
@Active bit
-->AS
-->BEGAIN
Insert Employers (InsuranceNumber, Ministry, Adress , PostalCode ,
Phone, Mobile , Email, UserName , [Password] , ContactPerson, EntryDate,
LastUpdateDate, IsDeleted, Active)
values (@InsuranceNumber, @Ministry, @Adress , @PostalCode ,
@Phone, @Mobile , @Email, @UserName , @[Password] , @ContactPerson, EntryDate,
@LastUpdateDate, @IsDeleted, @Active)
End
i still need to create Search , GetByID , GetByPage , GetList .. Stored Procedures please.. :) any help ?
Upvotes: 1
Views: 510
Reputation: 1455
Your question is not very clear.
The correct procedure code to insert a record:
CREATE PROCEDURE dbo.Employers_Insert
(
@InsuranceNumber nvarchar(10),
@Ministry nvarchar(100),
@Adress nvarchar(250),
@PostalCode varchar(50),
@Phone varchar(14),
@Mobile varchar(14),
@Email nvarchar(60),
@UserName nvarchar(50),
@Password nvarchar(50),
@ContactPerson nvarchar(250),
@EntryDate datetime,
@LastUpdateDate datetime,
@IsDeleted bit,
@Active bit
)
AS
BEGIN
INSERT INTO dbo.Employers
(
InsuranceNumber, Ministry, Adress, PostalCode,
Phone, Mobile, Email, UserName, [Password], ContactPerson, EntryDate,
LastUpdateDate, IsDeleted, ACTIVE
)
VALUES
(
@InsuranceNumber, @Ministry, @Adress, @PostalCode,
@Phone, @Mobile, @Email, @UserName, @Password, @ContactPerson, @EntryDate,
@LastUpdateDate, @IsDeleted, @Active
)
END
Also you need specify column EmployerId with IDENTITY specification if EmployerId is autoincrement or you need pass EmployerId as parameter of stored procedure.
You have problem with dbo.Employers_Insert or your need code for Search, GetByID, GetByPage, GetList ?
Upvotes: 1
Reputation: 10274
Based on your business requirements you can write a Search procedure as:
CREATE PROCEDURE sp_EmployersSearch
@Employerid int,-- Add here all the search parameters you'll send from application
@InsuranceNumber nvarchar(10),
@Ministry nvarchar(100),
@Adress nvarchar(250),
@PostalCode varchar(50),
@Phone varchar(14),
@Mobile varchar(14),
@Email nvarchar(60),
@UserName nvarchar(50),
@Password nvarchar(50),
@ContactPerson nvarchar(250),
@EntryDate datetime,
@LastUpdateDate datetime,
@IsDeleted bit,
@Active bit
AS
SELECT InsuranceNumber,-- Add here all the columns you want to send back to application
Ministry,
Adress ,
PostalCode ,
Phone,
Mobile ,
Email,
UserName ,
[Password] ,
ContactPerson,
EntryDate,
LastUpdateDate,
IsDeleted,
Active
FROM employers
WHERE (@Employerid IS NULL OR Employerid = @Employerid)
AND (@InsuranceNumber IS NULL OR InsuranceNumber LIKE '%' + @InsuranceNumber + '%')
AND (@Ministry IS NULL OR Ministry LIKE '%' + @Ministry + '%')
AND (@Adress IS NULL OR Adress LIKE '%' + @Adress + '%')
AND (@PostalCode IS NULL OR PostalCode = @PostalCode)
--You can add search conditions here based on your business requirements
Upvotes: 1