'LIKE' operator and SQL query

Download and get help for different MediaMonkey for Windows 4 Addons.

Moderators: Peke, Gurus

Octopod
Posts: 463
Joined: Tue Jun 10, 2003 9:09 am

'LIKE' operator and SQL query

Post by Octopod »

Hi,

I use the following from MS-Access with my MM DB (and it works):

Code: Select all

SELECT COUNT(*) FROM (SELECT DISTINCTROW Artists.Artist FROM Artists INNER JOIN Songs ON Songs.IDArtist = Artists.ID WHERE Songs.SongPath like '*Rock*')
While setting this in a MM script always return '0', can someone explain what's wrong? Problem with special characters like '*' when the string is parsed??

Code: Select all

Set QueryTest = SDB.Database.OpenSQL("SELECT COUNT(*) FROM (SELECT DISTINCTROW Artists.Artist FROM Artists INNER JOIN Songs ON Songs.IDArtist = Artists.ID WHERE Songs.SongPath Like '*Rock*')")
(Using "NOT LIKE" always returns the total number of albums...)

Thanks a lot!
jiri
Posts: 5419
Joined: Tue Aug 14, 2001 7:00 pm
Location: Czech Republic
Contact:

Post by jiri »

How do you continue after that 'Set QueryTest = ...' line? Check 'Sample New Window - Report.vbs' script, there is the following used:

Set QueryRes = SDB.Database.OpenSQL( "SELECT COUNT(*) FROM Songs")
Doc.Write "Track count: " & QueryRes.StringByIndex(0) & "<br>"

Do you mean that 'QueryRes.StringByIndex(0)' returns '0'?

Jiri
Octopod
Posts: 463
Joined: Tue Jun 10, 2003 9:09 am

Post by Octopod »

jiri wrote:How do you continue after that 'Set QueryTest = ...' line? Check 'Sample New Window - Report.vbs' script, there is the following used:

Set QueryRes = SDB.Database.OpenSQL( "SELECT COUNT(*) FROM Songs")
Doc.Write "Track count: " & QueryRes.StringByIndex(0) & "<br>"

Do you mean that 'QueryRes.StringByIndex(0)' returns '0'?

Jiri
I started my script from the sample you mentionned.
Here is the code:

Code: Select all

    Set QueryRock = SDB.Database.OpenSQL("SELECT COUNT(*) FROM (SELECT DISTINCTROW Artists.Artist FROM Artists INNER JOIN Songs ON Songs.IDArtist = Artists.ID WHERE Songs.SongPath Like '*Rock*')")
    Doc.Write "<LI>Rock: " &QueryRock.StringByIndex(0)& "</LI><br>"
    Set QueryPop = SDB.Database.OpenSQL("SELECT COUNT(*) FROM (SELECT DISTINCTROW Artists.Artist FROM Artists INNER JOIN Songs ON Songs.IDArtist = Artists.ID WHERE Songs.SongPath Like '*Pop*')")
    Doc.Write "<LI>Pop: " &QueryPop.StringByIndex(0)& "</LI><br>"
And yes the result is always '0' whenever i use the LIKE operator (ok if i use '=' and/or '<>', and so on...)
jiri
Posts: 5419
Joined: Tue Aug 14, 2001 7:00 pm
Location: Czech Republic
Contact:

Post by jiri »

Ok, I see. The problem is that LIKE syntax differs by connection method to DB. MM connects through ODBC and the correct syntax in this case is: SongPath Like '%Pop%'.

Anyway, shouldn't the query be rather based on Genre field?

Jiri
Octopod
Posts: 463
Joined: Tue Jun 10, 2003 9:09 am

Post by Octopod »

jiri wrote:MM connects through ODBC and the correct syntax in this case is: SongPath Like '%Pop%'.
Right. Works better now. :D Thanks.
jiri wrote:Anyway, shouldn't the query be rather based on Genre field?
This was an example :wink:
Post Reply