|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
hi,
i am pretty new with t-sql, cursors, and stored procs, so please bare with me. i am trying to update a table where num1,num2,num3, and num4 represent certain percentages based on the first select counts. i am looking at the breaktimes and if those breaktimes are in certain interval, i am trying to set the breaktype field to 'SOMETHING'. USE crap DECLARE @BreakDate datetime(8), @ProductID int(4), @dp1 numeric(9), @dp2 numeric(9), @dp3 numeric(9), @dp4 numeric(9), num1 numeric(9), num2 numeric(9), num3 numeric(9), num4 numeric(9), @event varchar(1024) SET @BreakDate = '11/30/2004' SET @ProductID= 4 SET @dp1 = 21600 SET @dp2 = 43200 SET @dp3 = 64800 SET @dp4 = 86400 SELECT COUNT(CASE WHEN BreakTime >= 0 AND BreakTime < @dp1 THEN 1 END) AS SC1, COUNT(CASE WHEN BreakTime >= @dp1 AND BreakTime < @dp2 THEN 1 END) AS SC2, COUNT(CASE WHEN BreakTime >= @dp2 AND BreakTime < @dp3 THEN 1 END) AS SC3, COUNT(CASE WHEN BreakTime >= @dp3 AND BreakTime < @dp4 THEN 1 END) AS SC4 FROM DenInt WHERE BreakType = 'SOFT' AND BreakDate = @BreakDate AND ProductID = @ProductID SET num1 = SC1 * 0.1 SET num2 = SC2 * 0.1 SET num3 = SC3 * 0.1 SET num4 = SC4 * 0.1 DECLARE cCan CURSOR FOR SELECT * FROM DenInt WHERE BreakDate = @BreakDate AND ProductID = @ProductID ORDER BY BreakTime OPEN cCan FETCH cCan INTO @event WHILE @@FETCH_STATUS = 0 BEGIN IF num1 > 0 AND BreakTime >= 0 AND BreakTime < dp1 UPDATE DenInt SET BreakType = 'SOMETHING' WHERE DIGridID = DIGridID END CLOSE cCan DEALLOCATE cCan however, when i run the code above it returns Server: Msg 170, Level 15, State 1, Line 4 Line 4: Incorrect syntax near 'num1'. Server: Msg 170, Level 15, State 1, Line 22 Line 22: Incorrect syntax near '='. Server: Msg 137, Level 15, State 1, Line 38 Must declare the variable '@event'. what am i doing wrong? thanks for the help in advance |
|
#2
|
|||
|
|||
|
@num1
@num2 @num3 @num4 ![]() |
|
#3
|
|||
|
|||
|
thanks, i made the change but it still gives the same error with @num1
|
|
#4
|
|||
|
|||
|
Change the declares as well as these:
SET num1 = SC1 * 0.1 SET num2 = SC2 * 0.1 SET num3 = SC3 * 0.1 SET num4 = SC4 * 0.1 |
![]() |
| Viewing: Dev Shed Forums > Databases > MS SQL Development > help with cursor |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|