【发布时间】:2012-04-24 17:05:54
【问题描述】:
我有一个用 C# 编写的应用程序,它连接到数据库并分析其数据,数据库存储有关执行自动化测试的信息,我想做的是检索那些满足上述给定条件的测试。但是我们有不同的项目,并且支持的项目越来越多,所以我不想为每个项目构建不同的过程,而是传递名称 - 第二个参数 deploy 作为参数,这样查询将取决于项目并将数据返回到申请,然后我会在报告中发送。
暂时是这样的:
CREATE PROCEDURE [dbo].[SuspectsForFalsePositive](@build_id INT, @deploy VARCHAR(25))
AS
BEGIN
SET NOCOUNT ON;
DECLARE @i int, @build int, @deployname varchar(25), @SQL varchar(max)
DECLARE @result table (tc int, fp float)
SET @i = 0
SET @build = @build_id
SET @deployname = @deploy
SET @SQL = 'insert '+@result+'select testcase_id, fail_percentage FROM [BuildTestResults].[dbo].['+@deployname+'TestCaseExecution]
where build_id = @build and fail_percentage >= 70'
--INSERT @result select testcase_id, fail_percentage FROM [BuildTestResults]
--.[dbo].[ABCTestCaseExecution]
--where build_id = @build and fail_percentage >= 70
--commented works
EXEC(@SQL)
WHILE (@@rowcount = 0)
BEGIN
SET @build = @build - 1
EXEC(@SQL)
--INSERT @result select testcase_id, fail_percentage FROM [BuildTestResults].[dbo]. --[ABCTestCaseExecution]
--where build_id = @build and fail_percentage >= 70
--commented works
END
select * from @result order by fp DESC
END
GO
感谢您的建议!
【问题讨论】:
-
“项目”如何存储在数据库中?不同的表?
-
我建议你阅读 Erland Sommarskog 的 The curse and blessings of dynamic SQL。
标签: sql sql-server-2008 stored-procedures concatenation