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 |
|
adr3nal1n
Starting Member
2 Posts |
Posted - 2010-09-06 : 10:04:53
|
| Hi,I am new to SQL and have read multiple online tutorials but am struggling to form a query to match similar strings in a field and then display the results.I have a database containing filenames, these files either end in .txt or .xls I would like to be able to query the database to display only filenames that have both .txt and .xls extensions.I have tried the following but it produces no output and I know I have some files that end in both extensions (e.g. Fred.txt and Fred.xls).select Filename from files where Filename like '%.txt' and Filename like '%.xls';Apologies if this is a trivial query, I am still very much a novice and would appreciate some direction as to where I am going wrong.Thanks in advance for any help. |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-09-06 : 10:13:00
|
| select parsename(Filename,2) from fileswhere Filename like '%.txt' or Filename like '%.xls'group by parsename(Filename,2) having count(distinct parsename(Filename,1) )=2MadhivananFailing to plan is Planning to fail |
 |
|
|
adr3nal1n
Starting Member
2 Posts |
Posted - 2010-09-06 : 10:25:36
|
| Thanks very much for your help and the prompt reply, am now reading through the query so I can workout the logic of it as this will help me with developing further queries. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-09-07 : 04:36:09
|
quote: Originally posted by adr3nal1n Thanks very much for your help and the prompt reply, am now reading through the query so I can workout the logic of it as this will help me with developing further queries.
You are welcome MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|