1

下面 UPDATE A iam 更新 facot Sqares 表 -iam 使用 sqare 表中的 updatd 因子来计算参数中的最终值

DECLARE @Year   char(8) = '2017';

WITH E1 AS(
   SELECT N FROM (VALUES(0),(0),(0),(0),(0),(0),(0),(0),(0),(0)) E(N)
),
E3 AS(
   SELECT a.N FROM E1 a, E1 b, E1 c
),
cteTally AS(
   SELECT TOP (360) DATEADD( dd, (ROW_NUMBER() OVER( ORDER BY (SELECT NULL)) - 1), CAST(@Year AS date))  myDate
   FROM E3
),
weekDays AS(
   SELECT myDate, ROW_NUMBER() OVER(PARTITION BY MONTH(myDate) ORDER BY myDate) rn
   FROM cteTally
   WHERE DATENAME( WEEKDAY, myDate) NOT IN ('Saturday', 'Sunday')
),
    Final as(
SELECT 
 myDate StartDay,
 datename(dw,myDate) Name, 

 DATEADD(dd,19,myDate) EndDay,
   DATEADD(MM, DATEDIFF(MM, 0, myDate), 0) FirstDay
FROM weekDays
WHERE rn = 1
)

SELECT FirstDay,StartDay,Name as StartName,

case when Name='Monday' THEN DATEADD(dd,18,StartDay)
     when Name='Tuesday' THEN DATEADD(dd,17,StartDay)
     when Name='Wednesday' THEN DATEADD(dd,16,StartDay)
     when Name='Thursday' THEN DATEADD(dd,15,StartDay)
     when Name='Friday' THEN DATEADD(dd,14,StartDay)

          ELSE NULL  END AS EndDate,


          case when Name='Monday' THEN datename(dw,DATEADD(dd,18,StartDay))
     when Name='Tuesday' THEN datename(dw,DATEADD(dd,17,StartDay))
     when Name='Wednesday' THEN datename(dw,DATEADD(dd,16,StartDay))
     when Name='Thursday' THEN datename(dw,DATEADD(dd,15,StartDay))
     when Name='Friday' THEN datename(dw,DATEADD(dd,14,StartDay))

          ELSE NULL  END AS EndName
 into #Dates FROM Final
4

3 回答 3

0

声明一个参数@factor。将第一条语句更改为set @factor =select B.candy/b.randy ...... 然后在没有连接的情况下进行更新。(使用@factor)调试和分析@factor 以选择您的工作。或者,您可以在第二次更新中使用 (nolock) 但请记住,您没有提交您的事务,因为它看起来是在最后一次更新之后(您的“问题”看起来像您在事务中并且您的第一次更新不会在第二次更新之前提交,因此您再次选择尚未更新的表)

于 2013-09-14T08:08:41.923 回答
0

这可能是由于数据类型转换而发生的。

请检查c。finalvalue 可以保存/插入/检索(成本*因子)的返回类型。

Sql server 更新将尽其所能,但需要验证数据类型。

于 2013-09-14T19:31:30.037 回答
0

DECLARE @StartDate date DECLARE @EndDate date DECLARE @Cursor CURSOR SET @Cursor = CURSOR FOR select StartDay,EndDate from #Dates

OPEN @Cursor FETCH NEXT FROM @Cursor INTO @StartDate,@EndDate WHILE @@FETCH_STATUS = 0 BEGIN

INSERT INTO #Dest select @StartDate StartDate,@EndDate EndDate, Max(high) High,min(low) Low from #Results where date between @StartDate and @EndDate FETCH NEXT FROM @Cursor INTO @StartDate,@EndDate END CLOSE @Cursor DEALLOCATE @Cursor SELECT B.[open],a.* FROM #Dest A JOIN #Results B ON A.StartDate=B.dATE

于 2017-07-25T19:49:56.170 回答