![]() |
| |||||||
| Sponsored Links |
![]() | « Previous Thread | Next Thread » |
| | LinkBack | Thread Tools | Display Modes |
|
#1
| ||||
| ||||
| OK, so this is one query I can never seem to wrap my head around. I have a table with 3 fields (that are interesting), none unique. - ProfileID uniqueidentifier - DateAdded datetime - PrimaryLvl int Right now for all records PrimaryLvl is NULL. I need to run an update query to set PrimaryLvl = 1 the earliest record (defined by DateAdded) for each unique ProfileID. I've done this before, but can never seem to quite remember how. The query I would use to return the records to be updated is: Code: Select ProfileId, min(DateAdded)
From aReallyBigButIndexedTable
Group By ProfileId
__________________ Wolffy ------------------------ Opinions expressed are my own and do not necessity reflect those of any sane person. Any code provided is intended to be an example and is provided AS IS. Rework for your specific environment may be required. Void where prohibited by law. Not valid in California. Your mileage may vary. |
| Sponsored Links |
|
#2
| ||||
| ||||
| I'm not 100% on this, but maybe something like: Code: UPDATE aReallyBigButIndexedTable SET primaryLvl = 1 IN (Select ProfileId, min(DateAdded)
From aReallyBigButIndexedTable
Group By ProfileId)
__________________ jmurrayhead If you agree with me... click the icon! If my post solved your problem, click the button in the lower right-hand corner of the post.Join our Folding team: DeveloperBarn Folding |
|
#3
| ||||
| ||||
| Just after I posted, I found the answer. I'll put it here so I know where to look the next time; Code: UPDATE tempInterests
SET PrimaryLvl = #tmp.One
FROM tempInterests
JOIN (
SELECT ot.ProfileId, min(ot.DateAdded) [DateAdded], 1 as One
FROM tempInterests ot
GROUP BY ot.ProfileId
) #tmp
ON #tmp.ProfileId = tempInterests.ProfileId
AND #tmp.DateAdded = tempInterests.DateAdded
(FWIW, I prolly coulda put PrimaryLvl = 1 and it would have worked, but I haven't tried that yet) |
![]() |
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| 2nd UpdatePanel won't update | Shem | .Net Development | 19 | July 10th, 2008 09:48 AM |
| Update Panel | Shem | .Net Development | 3 | July 10th, 2008 04:37 AM |
| update gridview dynamically | peebman2000 | .Net Development | 27 | May 8th, 2008 10:03 PM |
| Update sql connection string in web config | peebman2000 | .Net Development | 5 | April 18th, 2008 12:23 PM |