Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
I'm a rookie's rookie with SQL, and I'm trying what should be a pretty simple select.My table has 5 columns: FragmentNum, FragmentText, LocaleID, RevisionNum, and Status.In plain language, what I need to find is this:Select all rows from dbo.viewFragmentTextStatusWhere the FragmentText column contents for LocaleID 9 match the column contents for any other LocaleIDAnd where the RevisionNum evaluated for the criteria above is the highest of all those available for each LocaleID And where the status = activeBasically, if things are set up the way they should be, the most recent text in locale 9 should be in English, and the most recent text for the other locale IDs should be in their respective languages, not in English. I'm trying to find fragment IDs where that isn't the case.Is there some relatively simple syntax to do that?Thanks!!!Kent
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2010-02-04 : 03:25:52
do you mean this?
SELECT FragmentTextFROM(SELECT ROW_NUMBER() OVER (PARTITION BY LocaleID ORDER BY RevisionNum DESC) AS rn,FragmentNum, FragmentText, LocaleID, RevisionNum, StatusFROM dbo.viewFragmentTextStatus)tWHERE rn=1GROUP BY FragmentTextHAVING COUNT(DISTINCT LocaleID) >1AND SUM(CASE WHEN LOcaleID=9 THEN 1 ELSE 0 END) <> 0