Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2003-09-22 : 07:32:23
|
| Matt writes "I played around with a cursor but am not sure how to have the 'total_days' column add the value of 1 to each day that passes in a while statement. I don't uses cursors much, so I'm a bit rusty. Any help would be greatly appreciated. Here is my table:CREATE TABLE #DAYS_IN_FA (UNIT_SN VARCHAR(15), SHIP_DATE DATETIME, TOTAL_DAYS INT, STATUS VARCHAR(20))-- While the status of the drive was 'incomplete', add '1' to the-- total days that a drive was at FA. WHILE STATUS = 'INCOMPLETE' BEGIN SET @TOTAL_DAYS = @TOTAL_DAYS + 1 INSERT INTO DAYS_IN_FA VALUES (@UNIT_SN, @SHIP_DATE, @TOTAL_DAYS) FETCH NEXT FROM TD_CURSOR INTO @UNIT_SN, @SHIP_DATE, @TOTAL_DAYS END" |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2003-09-22 : 08:06:08
|
| Please give us some sample data in the form of INSERT statements, what you are trying to calculate and how, and what your results should look like .... I personally don't follow your logic. i.e.,INSERT INTO #DAYS_IN_FA (c1,c2,c3) VALUES ( blah blah)INSERT INTO #DAYS_IN_FA (c1,c2,c3) VALUES ( blah blah)INSERT INTO #DAYS_IN_FA (c1,c2,c3) VALUES ( blah blah)..etc..Goal: I want to return the total # of days since ... blah blah .. for each ... blah blahExpected result (based on sample data):blah blah blahTrust me -- you will get answers quickly and accurately if you give us some info !!Thanks!- Jeff |
 |
|
|
dsdeming
479 Posts |
Posted - 2003-09-23 : 08:40:40
|
| Are you trying to find the number of days a row is in its current status, days spent in each status it ever had, or days spent in one particular status?Dennis |
 |
|
|
|
|
|
|
|