【发布时间】:2014-02-28 13:35:43
【问题描述】:
我是 T-SQL 存储过程的新手,我正在尝试调用我的存储过程在我的 asp 页面上工作。我不知道该怎么做,我只是为我的 Select 语句创建一个 SQL 字符串,还是必须包含所有声明变量。我在下面发布了我的声明和选择声明。感谢您的帮助。
DECLARE @CasesPerHour decimal(18,2);
Declarations
DECLARE @Line1Start datetime;
DECLARE @Line1Breaks decimal(10,2);
DECLARE @Line1ScaleCount int;
DECLARE @Line1Scale1Percentage varchar(10);
DECLARE @Line1Scale2Percentage varchar(10);
DECLARE @Line1Scale3Percentage varchar(10);
DECLARE @Line1Scale4Percentage varchar(10);
DECLARE @Line1Scale5Percentage varchar(10);
DECLARE @Line1Scale6Percentage varchar(10);
DECLARE @Line1Scale7Percentage varchar(10);
DECLARE @Line1Percentage varchar(10);
DECLARE @Line1TargetCaseCount decimal(10,2);
Set statement
SET @CasesPerHour = 70.00
--Line 1 Sets
SET @Line1Start = (SELECT TOP 1 PrintDateTime
FROM CompletedCaseManifest
WHERE LineNumber = 1 and PrintDateTime > (CASE WHEN (cast(getdate() as time(0)) < '06:00:00' OR cast(getdate() as time(0)) > '17:15:00') then (CASE WHEN cast(getdate() as time(0)) < '06:00:00' then DATEADD(day, DATEDIFF(day, 1, GETDATE()), '17:15:00') else DATEADD(day, DATEDIFF(day, 0, GETDATE()), '17:15:00') end) else DATEADD(day, DATEDIFF(day, 0, GETDATE()), '06:00:00') end))
SET @Line1Breaks = ISNULL((SELECT SUM(BreakLength) FROM BreakTracker WHERE LineNumber = 1 AND BreakStartTime > @Line1Start), 0)/60.00
SET @Line1ScaleCount = (SELECT COUNT(Distinct ScaleNumber) FROM CompletedCaseManifest Where LineNumber = 1 and PrintDateTime > @Line1Start)
SET @Line1TargetCaseCount = (((datepart(minute,convert(varchar(8),cast(getdate() - @Line1Start as time(0))))/60.00)
+ datepart(hour,convert(varchar(8),cast(getdate() - @Line1Start as time(0)))) - @Line1Breaks)*@CasesPerHour)
SET @Line1Scale1Percentage = Convert(decimal(10,2),((SELECT COUNT(CaseID) FROM CompletedCaseManifest WHERE LineNumber = 1 and ScaleNumber = 1 and CaseVoided = 0 and PrintDateTime > @Line1Start)/@Line1TargetCaseCount)*100)
SET @Line1Scale2Percentage = Convert(decimal(10,2),((SELECT COUNT(CaseID) FROM CompletedCaseManifest WHERE LineNumber = 1 and ScaleNumber = 2 and CaseVoided = 0 and PrintDateTime > @Line1Start)/@Line1TargetCaseCount)*100)
SET @Line1Scale3Percentage = Convert(decimal(10,2),((SELECT COUNT(CaseID) FROM CompletedCaseManifest WHERE LineNumber = 1 and ScaleNumber = 3 and CaseVoided = 0 and PrintDateTime > @Line1Start)/@Line1TargetCaseCount)*100)
SET @Line1Scale4Percentage = Convert(decimal(10,2),((SELECT COUNT(CaseID) FROM CompletedCaseManifest WHERE LineNumber = 1 and ScaleNumber = 4 and CaseVoided = 0 and PrintDateTime > @Line1Start)/@Line1TargetCaseCount)*100)
SET @Line1Scale5Percentage = Convert(decimal(10,2),((SELECT COUNT(CaseID) FROM CompletedCaseManifest WHERE LineNumber = 1 and ScaleNumber = 5 and CaseVoided = 0 and PrintDateTime > @Line1Start)/@Line1TargetCaseCount)*100)
SET @Line1Scale6Percentage = Convert(decimal(10,2),((SELECT COUNT(CaseID) FROM CompletedCaseManifest WHERE LineNumber = 1 and ScaleNumber = 6 and CaseVoided = 0 and PrintDateTime > @Line1Start)/@Line1TargetCaseCount)*100)
SET @Line1Scale7Percentage = Convert(decimal(10,2),((SELECT COUNT(CaseID) FROM CompletedCaseManifest WHERE LineNumber = 1 and ScaleNumber = 7 and CaseVoided = 0 and PrintDateTime > @Line1Start)/@Line1TargetCaseCount)*100)
SET @Line1Percentage = Convert(decimal(10,2),((SELECT COUNT(CaseID) FROM CompletedCaseManifest WHERE LineNumber = 1 and CaseVoided = 0 and PrintDateTime > @Line1Start)/(@Line1TargetCaseCount*@Line1ScaleCount))*100)
选择语句
Select @Line1Scale1Percentage + '%' as Line1Scale1,
@Line1Scale2Percentage + '%' as Line1Scale2,
@Line1Scale3Percentage + '%' as Line1Scale3,
@Line1Scale4Percentage + '%' as Line1Scale4,
@Line1Scale5Percentage + '%' as Line1Scale5,
@Line1Scale6Percentage + '%' as Line1Scale6,
@Line1Scale7Percentage + '%' as Line1Scale7,
@Line1Percentage + '%' as Line1Average,
【问题讨论】:
-
如果过程没有声明的输入或输出参数,你不提供任何。如果它从选择中返回行; How to: Execute a Stored Procedure that Returns Rows
标签: c# asp.net tsql stored-procedures