Sign in to follow this  
Followers 0
Oldschool

Quick SQL question

7 posts in this topic

This code works perfectly in Access:

SELECT [item_id] FROM [items] WHERE [item_name] LIKE '*SomeItemName*';

This code works in Autoit:

$ItemName = "SomeItemName"
$sQuery = "SELECT [item_id] FROM [items] WHERE [item_name] =" & Chr(34) & $ItemName & Chr(34) &";"oÝ÷ Ù8b±Êyö¢È§ëh"Ö®¶­sbb33c´FVÔæÖRÒgV÷Cµ6öÖTFVÔæÖRgV÷C°¢b33c·5VW'ÒgV÷Cµ4TÄT5B¶FVÕöEÒe$ôÒ¶FV×5ÒtU$R¶FVÕöæÖUÒÄ´Rb33²¢gV÷C²fײ6"3Bfײb33c´FVÔæÖRfײ6"3BfײgV÷C²¢b33²²gV÷CoÝ÷ Ù«­¢+ØÀÌØí%ѵ9µôÅÕ½ÐíM½µ%ѵ9µÅÕ½Ðì(ÀÌØíÍEÕÉäôÅÕ½ÐíM1
Pm¥Ñµ}¥tI=4m¥ÑµÍt]!Im¥Ñµ}¹µt1%-ÅÕ½ÐìµÀì
¡È Ì䤵Àì
¡È ÐȤµÀì
¡È ÌФµÀìÀÌØí%ѵ9µµÀì
¡È ÌФµÀì
¡È ÐȤµÀì
¡È Ì䤵ÀìÅÕ½ÐììÅÕ½ÐoÝ÷ Ù«­¢+ØÀÌØí%ѵ9µôÅÕ½ÐíM½µ%ѵ9µÅÕ½Ðì(ÀÌØíÍEÕÉäôÅÕ½ÐíM1
Pm¥Ñµ}¥tI=4m¥ÑµÍt]!Im¥Ñµ}¹µt1%-ÅÕ½ÐìµÀìÅÕ½ÐìÌäì¨ÅÕ½ÐìµÀì
¡È ÌФµÀìÀÌØí%ѵ9µµÀì
¡È ÌФµÀìÅÕ½Ðì¨ÌäìÅÕ½ÐìµÀìÅÕ½ÐììÅÕ½Ðì

Where am I off here?

Share this post


Link to post
Share on other sites

#2 ·  Posted (edited)

@Oldschool.....

Try this..

$sQuery = "SELECT [item_id] FROM [items] WHERE [item_name] LIKE '*" & $ItemName & "*' ;" (Take the Chr(34) out because you already have single quotes.

When you are using "like" u will need to use the % symbol not the * symbol. (This will be the case if you are using this query in Oracle)

Edited by DjDeep00

Share this post


Link to post
Share on other sites

@Oldschool.....

Try this..

$sQuery = "SELECT [item_id] FROM [items] WHERE [item_name] LIKE '*" & $ItemName & "*' ;" (Take the Chr(34) out because you already have single quotes.

When you are using "like" u will need to use the % symbol not the * symbol. (This will be the case if you are using this query in Oracle)

Does not work...

It's * in MSAccess

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

this fails too...

$sQuery = 'SELECT [item_id] FROM [items] WHERE [item_name] LIKE ' & "'*" & $ItemName & "*'" &';'oÝ÷ Ù«­¢+ØÀÌØíÍEÕÉäôÌäíM1
Pm¥Ñµ}¥tI=4m¥Ñµt]!Im¥Ñµ}¹µt1%-ÌäìµÀìÌäìÅÕ½Ðì¨ÌäìµÀìÀÌØí%ѵ9µµÀìÌäì¨ÅÕ½ÐììÌäì
Edited by Oldschool

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

DjDeep is correct. You should be using percent, not asterisk.

BTW - The last two examples you posted are ugly and it should work just like this:

$ItemName = "SomeItemName"
$sQuery = "SELECT [item_id] FROM [items] WHERE [item_name] ='%" & $ItemName &"%';"
Edited by weaponx

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

DjDeep is correct. You should be using percent, not asterisk.

BTW - The last two examples you posted are ugly and it should work just like this:

$ItemName = "SomeItemName"
$sQuery = "SELECT [item_id] FROM [items] WHERE [item_name] ='%" & $ItemName &"%';"ƒoÝŠ÷ Ûú®¢×ˆv‰÷öÙ'£!É»­¶¬zw^vêp¢¹"ž®¶ˆ­sbb33c·5VW'’ÒgV÷Cµ4TÄT5B¶—FVÕö–EÒe$ôÒ¶—FV×5Òt„U$R¶—FVÕöæÖUÒÄ”´RgV÷C²fײgV÷C²b33“²RgV÷C²fײb33c´—FVÔæÖRfײgV÷C²Rb33“²²gV÷C

It's crazy because in MSAccess itself the query with % produces no desired results. You have to use *

Thank you friends.

Edited by Oldschool

Share this post


Link to post
Share on other sites

DjDeep is correct. You should be using percent, not asterisk.

BTW - The last two examples you posted are ugly and it should work just like this:

$ItemName = "SomeItemName"
$sQuery = "SELECT [item_id] FROM [items] WHERE [item_name] ='%" & $ItemName &"%';"oÝ÷ Ûú®¢×v÷öÙ'£!É»­¶¬zw^vêp¢¹"®¶­sbb33c·5VW'ÒgV÷Cµ4TÄT5B¶FVÕöEÒe$ôÒ¶FV×5ÒtU$R¶FVÕöæÖUÒÄ´RgV÷C²fײgV÷C²b33²RgV÷C²fײb33c´FVÔæÖRfײgV÷C²Rb33²²gV÷C

It's crazy because in MSAccess itself the query with % produces no desired results. You have to use *

Thank you friends

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0