April 30, 2009 at 2:00 pm
I have many databases in my server where the name goes something like
mnfkasjh_PA
hsdfgadsaffg_CA
uhakjfaf_KY
most of them have post fix as _PA etc.., how do i select only those databases.
April 30, 2009 at 2:07 pm
Hi
If you just mean SELECT from sys.databases try this:
SELECT * FROM sys.databases WHERE name LIKE '%/_PA' ESCAPE '/'
Otherwise you should provide more information 😉
Greets
Flo
April 30, 2009 at 2:09 pm
when you say " _PA " it a state abbrevation, so i may need find all database which has post fix of _state, its not just " _PA"
April 30, 2009 at 2:12 pm
Then you just need to change the letters in that part of the select to whatever state abbreviation is appropriate.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
April 30, 2009 at 2:13 pm
If the postfix is always to characters use this:
SELECT * FROM sys.databases WHERE name LIKE '%/___' ESCAPE '/'
If only a "_" has to be found use this:
SELECT * FROM sys.databases WHERE name LIKE '%/_%' ESCAPE '/'
If anything else... more information 🙂
Greets
Flo
April 30, 2009 at 3:52 pm
Would this work for you? It will also find 2 letter combinations that aren't valid US state abbreviations, though...
SELECT * FROM sys.databases WHERE name LIKE '%[_][A-Z][A-Z]'
bc
[font="Arial Narrow"]bc[/font]
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply