适合经常改变where子句的代码
SQL:
create proc procBP_Cost_UpdateCost
as
SELECT a.ModelGroupID, a.ProductCost
FROM T_ProductCost AS a INNER JOIN
T_BPCost ON a.ModelGroupID = T_BPCost.ModelGroupID
WHERE EXISTS (
SELECT MAX(CONVERT(int, PCYear + PCMonth)) AS Version, ModelGroupID
FROM T_ProductCost
GROUP BY ModelGroupID, ProductCostID
HAVING (MAX(CONVERT(int, PCYear + PCMonth)) = CONVERT(int, a.PCYear + a.PCMonth)) AND (a.CostCommit = 'Y'))
as
SELECT a.ModelGroupID, a.ProductCost
FROM T_ProductCost AS a INNER JOIN
T_BPCost ON a.ModelGroupID = T_BPCost.ModelGroupID
WHERE EXISTS (
SELECT MAX(CONVERT(int, PCYear + PCMonth)) AS Version, ModelGroupID
FROM T_ProductCost
GROUP BY ModelGroupID, ProductCostID
HAVING (MAX(CONVERT(int, PCYear + PCMonth)) = CONVERT(int, a.PCYear + a.PCMonth)) AND (a.CostCommit = 'Y'))
后台:

public DataSet GetDataSetbyProc(string procName)
{
#region 注释
/*********************************************\
*功能:
* 执行存储过程,返回DataSet
*返回: DataSet
Vegas 2008 07 16
\********************************************/
#endregion
SqlDataAdapter sda = new SqlDataAdapter(procName, connStr);
sda.SelectCommand.CommandType = CommandType.StoredProcedure;
DataSet ds = new DataSet();
sda.Fill(ds);
return ds;
}
{
#region 注释
/*********************************************\
*功能:
* 执行存储过程,返回DataSet
*返回: DataSet
Vegas 2008 07 16
\********************************************/
#endregion
SqlDataAdapter sda = new SqlDataAdapter(procName, connStr);
sda.SelectCommand.CommandType = CommandType.StoredProcedure;
DataSet ds = new DataSet();
sda.Fill(ds);
return ds;
}
相关文章
暂无评论...