Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Insert Problem

Status
Not open for further replies.

emblewembl

Programmer
May 16, 2002
171
GB
I have a stored procedure which is called from a web site at say every 2 minutes which returns a set of rows of data about entries in a race. If one of the fields in any of the entries is set to 1 rather than 0 I would like to perform the following actions:

1. Get the related id for the entry.
2. Extract some data from a view for this id.
3. Update another table with the new data.
4. Set the initial field back to 0 so that once the update has been done it won't be done again.

In my initial select statement it's as though i want to have something like:

Code:
select m.id, m.b, m.c (case when m.c = 1 then 
    update myTable
    set col = valCalculated
    where id = m.id)
from mainTable m
where raceid = 12345

but i know i can' embed an update statement like this. Incidentally there may be more than one row with m.c set to 1 in each race.

I am stuck... can anyone help?

i love chocolate
 
If you need to do steps in your code based on whether something exists or not then use the if statement not the case. Example{code]
if (select codefield from table1) = 1
Begin
Perform an insert or update here
End
Else
Begin
Do something different
End

select what you need now that the tables have the data
{/code]

Questions about posting. See faq183-874
Click here to help with Hurricane Relief
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top