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.
Author |
Topic |
phencerx
Starting Member
2 Posts |
Posted - 2008-02-04 : 16:33:00
|
So I've hit a brick wall. I'm working on creating a script to do some database cleanup but I'm having problems getting a query to bring the exact data I want.When I run:select distinct(SUBSTRING(description,1,(LEN(description) - 8)))as descriptionfrom documenttemplateswhere description like '%(%)'I get resultsdescription -------------------------------------------------- Agreement to Provide Insurance Appraisal Appraisal Letter Appraisal Review Auto Transfer Authorization Business Purpose Statement CIP Addendum Credit Memo Disbursement DOT Environmental Report FCRA Post-closing Notice Flood Verification Good Faith Estimate HMDA Insurance Disclosure Itemization of Amount Financed Loan Agreement Loan Doc Checklist Note Notice of Availability of Title Notice to Home Loan App - Credi Power of Attorney Pre-closing Docs Right to CancelSECURITY AGREEMENT Settlement Statement Settlement Stmt / Disbursement TILTitle Policy UCC-1But when I add in the ID field to the queryselect (SUBSTRING(description,1,(LEN(description) - 8)))as description, idfrom documenttemplateswhere description like '%(%)'My results turn into:description id -------------------------------------------------- ----------- Agreement to Provide Insurance 175Agreement to Provide Insurance 194Agreement to provide insurance 27Agreement to Provide Insurance 276Agreement to Provide Insurance 277Agreement to provide Insurance 40Agreement to provide Insurance 51Agreement to Provide Insurance 56Agreement to Provide Insurance 59Appraisal 103Appraisal 115Appraisal 79Appraisal 90etc.I understand why it's doing this, but I'm at a loss to where I can only pull the first instance of each document with it's id so I could get:description id -------------------------------------------------- ----------- Agreement to Provide Insurance 175Appraisal 103etc.I'm sure it's something simple that I'm overlooking, but any help would be much appreciated.Thanks |
|
hey001us
Posting Yak Master
185 Posts |
Posted - 2008-02-04 : 17:02:46
|
here you go:select (SUBSTRING(description,1,(LEN(description) - 8)))as description, max(id)from documenttemplateswhere description like '%(%)'group by (SUBSTRING(description,1,(LEN(description) - 8)))hey |
 |
|
phencerx
Starting Member
2 Posts |
Posted - 2008-02-04 : 17:07:55
|
Like I said, something simple that I was overlooking.Thanks hey. |
 |
|
|
|
|
|
|