Iran58
سه شنبه 23 تیر 1394, 08:30 صبح
سلام
لطفا نظر خودتان را مورد اینگونه sp نوشتن بیان بفرمایید(نقاطضعف وقدرت)
ALTER Procedure [dbo].[S_Personnel_SelectList]
/* Input Parameters */
@Sex tinyint,
@BCID varchar(10),
@BirthDate varchar(10),
@BirthCity nvarchar(100),
@Allegiance nvarchar(100),
@Address nvarchar(100),
@Tel varchar(50),
@MobileNo varchar(50),
@OrgChartID varchar(50),
@OrgChartName varchar(100),
@JobId varchar(50),
@JobName nvarchar(100),
@PositionName nvarchar(100),
@Modiriat nvarchar(100),
@Edare nvarchar(100),
@Bakhsh nvarchar(100)
AS
Set NoCount ON
/* Variable Declaration */
Declare @SQLQuery AS NVarchar(4000)
Declare @ParamDefinition AS NVarchar(2000)
/* Build the Transact-SQL String with the input parameters */
Set @SQLQuery = 'Select * From V_PersonnelList where (1 = 1) '
/* check for the condition and build the WHERE clause accordingly */
If @Sex is not null
Set @SQLQuery = @SQLQuery + ' And (Sex = @Sex)'
If @BCID <> ''
Set @SQLQuery = @SQLQuery + ' And (BCID like' + '''%''' + '+ @BCID +' + '''%''' + ')'
If @BirthDate <> ''
Set @SQLQuery = @SQLQuery + ' And (BirthDate = @BirthDate)'
If @Allegiance <> ''
Set @SQLQuery = @SQLQuery + ' And (Allegiance like' + '''%''' + '+ @Allegiance +' + '''%''' + ')'
If @OrgChartName <> ''
If @Address <> ''
Set @SQLQuery = @SQLQuery + ' And (Address like' + '''%''' + '+ @Address +' + '''%''' + ')'
If @Tel <> ''
Set @SQLQuery = @SQLQuery + ' And (Tel like' + '''%''' + '+ @Tel +' + '''%''' + ')'
If @MobileNo <> ''
Set @SQLQuery = @SQLQuery + ' And (MobileNo like' + '''%''' + '+ @MobileNo +' + '''%''' + ')'
/* Specify Parameter Format for all input parameters included
in the stmt */
Set @ParamDefinition = '
@Sex tinyint,
@BCID varchar(10),
@BirthDate varchar(10),
@BirthCity nvarchar(100),
@Allegiance nvarchar(100),
@Address nvarchar(100),
@Tel varchar(50),
@MobileNo varchar(50)
/* Execute the Transact-SQL String with all parameter value's
Using sp_executesql Command */
Execute sp_Executesql @SQLQuery,
@ParamDefinition,
@Sex,
@BCID,
@BirthDate,
@BirthCity,
@Allegiance,
@Address,
@Tel,
@MobileNo
If @@ERROR <> 0 GoTo ErrorHandler
Set NoCount OFF
Return(0)
ErrorHandler:
Return(@@ERROR)
لطفا نظر خودتان را مورد اینگونه sp نوشتن بیان بفرمایید(نقاطضعف وقدرت)
ALTER Procedure [dbo].[S_Personnel_SelectList]
/* Input Parameters */
@Sex tinyint,
@BCID varchar(10),
@BirthDate varchar(10),
@BirthCity nvarchar(100),
@Allegiance nvarchar(100),
@Address nvarchar(100),
@Tel varchar(50),
@MobileNo varchar(50),
@OrgChartID varchar(50),
@OrgChartName varchar(100),
@JobId varchar(50),
@JobName nvarchar(100),
@PositionName nvarchar(100),
@Modiriat nvarchar(100),
@Edare nvarchar(100),
@Bakhsh nvarchar(100)
AS
Set NoCount ON
/* Variable Declaration */
Declare @SQLQuery AS NVarchar(4000)
Declare @ParamDefinition AS NVarchar(2000)
/* Build the Transact-SQL String with the input parameters */
Set @SQLQuery = 'Select * From V_PersonnelList where (1 = 1) '
/* check for the condition and build the WHERE clause accordingly */
If @Sex is not null
Set @SQLQuery = @SQLQuery + ' And (Sex = @Sex)'
If @BCID <> ''
Set @SQLQuery = @SQLQuery + ' And (BCID like' + '''%''' + '+ @BCID +' + '''%''' + ')'
If @BirthDate <> ''
Set @SQLQuery = @SQLQuery + ' And (BirthDate = @BirthDate)'
If @Allegiance <> ''
Set @SQLQuery = @SQLQuery + ' And (Allegiance like' + '''%''' + '+ @Allegiance +' + '''%''' + ')'
If @OrgChartName <> ''
If @Address <> ''
Set @SQLQuery = @SQLQuery + ' And (Address like' + '''%''' + '+ @Address +' + '''%''' + ')'
If @Tel <> ''
Set @SQLQuery = @SQLQuery + ' And (Tel like' + '''%''' + '+ @Tel +' + '''%''' + ')'
If @MobileNo <> ''
Set @SQLQuery = @SQLQuery + ' And (MobileNo like' + '''%''' + '+ @MobileNo +' + '''%''' + ')'
/* Specify Parameter Format for all input parameters included
in the stmt */
Set @ParamDefinition = '
@Sex tinyint,
@BCID varchar(10),
@BirthDate varchar(10),
@BirthCity nvarchar(100),
@Allegiance nvarchar(100),
@Address nvarchar(100),
@Tel varchar(50),
@MobileNo varchar(50)
/* Execute the Transact-SQL String with all parameter value's
Using sp_executesql Command */
Execute sp_Executesql @SQLQuery,
@ParamDefinition,
@Sex,
@BCID,
@BirthDate,
@BirthCity,
@Allegiance,
@Address,
@Tel,
@MobileNo
If @@ERROR <> 0 GoTo ErrorHandler
Set NoCount OFF
Return(0)
ErrorHandler:
Return(@@ERROR)