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.
HiI am struggling with a query and would be grateful if anyone can help meThe problem is that some clients who have more than one lender in the table have the same CaseID but the Loan column goes from 1 to 2.I am trying to select all of the records that only have 1 loan and where they have more than one to ignore the record completly. A sample of the table is belowID CaseID Loan Lender45184 374946 1 Nat West Retail Banking Services45185 374946 2 First National Bank Plc45189 374961 1 Abbey National Mortgage Financ45190 374968 1 Mortgage Corporation45191 374971 1 Barclays Home Finance45192 374981 1 I Group Mortgages Ltd45205 375020 1 I Group Mortgages Ltd45206 375020 2 Blackhorse Finance Ltd45207 375018 1 I Group Mortgages Ltd45210 374982 2 citi financial45211 374982 2 welcome finance45217 375040 1 Abbey National Plc - Bradford45220 375043 1 citi financial europe plc45221 375043 2 welcome financefrom this data if I was just selecting the CaseID I would want the results of374961374968374971374981375018375040and to ignore374946375020374982375043Hope I have explained this clearly enoughThanks
pootle_flump
1064 Posts
Posted - 2009-03-17 : 12:12:01
[code]SELECT CaseID FROM myTGROUP BY CaseID HAVING COUNT(*) = 1[/code]???
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2009-03-17 : 13:12:42
if sql 2005 then
SELECT ID, CaseID, Loan, LenderFROM(SELECT ID, CaseID, Loan, Lender,COUNT(Loan) OVER (PARTITION BY CaseID) AS OccuranceFROM TABLE)tWHERE Occurance=1