I have a table that has a birthday in it along with a Stage field. Birthdate is a DateTime field and the Stage is a VarChar(50).
I put the Birthday in the table first, then I want to determine what stage the user is in. I have a function that looks up the stage based on how old the person is. For example:
Stage = Infant if < 1 year
Stage = Baby if > 1 year < and less 2 years
Stage = Child if > 2 years and < 12 years
Stage = Teenager if > 12 years and < 16 year
etc, etc...
The stored proc that returns the stage uses an out parameter and it's working just fine.
What I want to do is loop through each record in the table and update the Stage field for each record based on the birthday.
In ADO/VB I want to do this:
Here's the code I have so far but it's not updating the Stage field.
I'm not a T-SQL expert as you can probably tell. Thanks for looking and for any help you can provide.
Snaggs
tribesaddict@swbell.net
Life can only be understood backwards; but it must be lived forwards.
I put the Birthday in the table first, then I want to determine what stage the user is in. I have a function that looks up the stage based on how old the person is. For example:
Stage = Infant if < 1 year
Stage = Baby if > 1 year < and less 2 years
Stage = Child if > 2 years and < 12 years
Stage = Teenager if > 12 years and < 16 year
etc, etc...
The stored proc that returns the stage uses an out parameter and it's working just fine.
What I want to do is loop through each record in the table and update the Stage field for each record based on the birthday.
In ADO/VB I want to do this:
Code:
rs.Open "Person"
Do Until rs.EOF
rs!Stage = GetStage(rs!Birthday)
rs.Update
rs.MoveNext
Loop
rs.Close
Here's the code I have so far but it's not updating the Stage field.
Code:
/* Convert to Stage */
Declare tAvail Cursor For
SELECT GroupBirthdate, DateIn, Stage FROM tAvailable
OPEN tAvail
/* Determine and update the Stage */
FETCH NEXT FROM tAvail Into @GroupBirthDate, @DateIn, @Stage
WHILE @@FETCH_STATUS = 0
BEGIN
/* Get the stage based on the datein and the birthdate */
exec sp_GetStage @GroupBirthDate, @DateIn, @Stage out
I think I need something here to do the update. But what?
FETCH NEXT FROM tAvail Into @GroupBirthDate, @DateIn, @Stage
END
CLOSE tAvail
DEALLOCATE tAvail
GO
I'm not a T-SQL expert as you can probably tell. Thanks for looking and for any help you can provide.
Snaggs
tribesaddict@swbell.net
Life can only be understood backwards; but it must be lived forwards.