asp.net (C #) +sql Server three-tier architecture data access Scheme (ii)
Developer on Alibaba Coud: Build your first app with APIs, SDKs, and tutorials on the Alibaba Cloud. Read more ＞
asp.net|server| Schema | data stored procedures:
Function: Read function record according to certain condition
Date Created: 2004-01-13
ALTER PROCEDURE getscoresetting
@ScoreSettingID Int=-1,---set ID
@FunctionID Int=-1,---feature ID
@OperationID Int=-1,---action ID
@RoleTypeID int=-1,---role type
@BBSTypeID int=-1,---Type of forum
@Score Int=-1,---integral setting
@BB int=-1,---currency settings
@BuyType int=-1,---Purchase type 0: not Purchase type 1: One-time purchase 2: Repeat purchase
@FunctionState Int=-1---functional status
SET NOCOUNT on
DECLARE @strSQL NVARCHAR (1000)
SET @strSQL = ' SELECT * from [scoresetting] WHERE @ckScoreSettingID = @ckScoreSettingID '
---Add KeyWords Begin---
IF @ScoreSettingID <>-1
SET @strSQL = @strSQL + ' and scoresettingid= @ckScoreSettingID '
IF @FunctionID <>-1
SET @strSQL = @strSQL + ' and functionid= @ckFunctionID '
IF @OperationID <>-1
SET @strSQL = @strSQL + ' and OperationID = @ckOperationID '
IF @RoleTypeID <>-1
SET @strSQL = @strSQL + ' and Roletypeid = @ckRoleTypeID '
IF @BBSTypeID <>-1
SET @strSQL = @strSQL + ' and Bbstypeid = @ckBBSTypeID '
IF @Score <>-1
SET @strSQL = @strSQL + ' and Score = @ckScore '
IF @BB <>-1
SET @strSQL = @strSQL + ' and bb= @ckBB '
IF @BuyType <>-1
SET @strSQL = @strSQL + ' and buytype= @ckBuyType '
IF @FunctionState <>-1
SET @strSQL = @strSQL + ' and functionstate= @ckFunctionState '
---Add Where Key Word---
---Run SQL Begin---
EXECUTE sp_executesql @strSQL,
N ' @ckScoreSettingID INT,
@ckFunctionState INT ',
@ckScoreSettingID = @ScoreSettingID,
@ckFunctionID = @FunctionID,
@ckOperationID = @OperationID,
@ckRoleTypeID = @RoleTypeID,
@ckBBSTypeID = @BBSTypeID,
@ckScore = @Score,
@ckBB = @BB,
@ckBuyType = @BuyType,
@ckFunctionState = @FunctionState
---Run SQL End---
A little note:
This stored procedure dynamically creates a query statement based on whether the class of the data layer passes the corresponding parameter value, and then executes the SQL statement with the system's own stored procedure, and the advantage of executing the SQL statement with the system stored procedure is that the character can be automatically escaped. The benefits of dynamically creating query statements are very large, this will save us to write a lot of conditions to judge, especially for those who have a lot of tables, a combination of the situation is too much, and the use of stored procedures to create SQL statements dynamically created by the number of judgments and the number of fields is basically the same, here will give the parameters of the initial value, If it is not equal to the initial value, the data-tier class has passed the argument in, so that the query condition of the corresponding conditional character is added.
This article is an English version of an article which is originally in the Chinese language on aliyun.com and is provided for information purposes only. This website makes no representation or warranty of any kind, either expressed or implied, as to the accuracy, completeness ownership or
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
and provide relevant evidence. A staff member will contact you within 5 working days.