473,378 Members | 1,099 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

can anyone solve this sql query?

hi friends i need help in this sql query

i have table like,

id fid
__ _____
autonumber text

and i am storing values like

id fid
___________________________________
1 1,2,3,4,5

2 11,12,13,14,15

now to find values i am using query

sql = SELECT * FROM test12 WHERE `fid` LIKE ('%1%')

only problem in this query is it is selecting 1 and 11 and i require
only 1 as i am giving one in %1%
now any one have answer of this question then plz plz tell me ........

Oct 16 '06 #1
5 1575
hardik wrote:
hi friends i need help in this sql query

i have table like,

id fid
__ _____
autonumber text

and i am storing values like

id fid
___________________________________
1 1,2,3,4,5

2 11,12,13,14,15

now to find values i am using query

sql = SELECT * FROM test12 WHERE `fid` LIKE ('%1%')

only problem in this query is it is selecting 1 and 11 and i require
only 1 as i am giving one in %1%
now any one have answer of this question then plz plz tell me ........
It's too bad your Fid doesn't have a space between numbers. Then you
could test for " 1,".

Maybe you can create then call a function. Like
Where SplitFid([Fid],1) = True

Public Function SplitFid(varFid As Variant, _
varSearch As Variant) as Boolean
and SplitFid would parse out the elements if the Fid using the Split
function to parse out each element of Fid and then enumerate the list
and see if the value to search for is in the list.
Oct 16 '06 #2
hardik wrote:
id fid
___________________________________
1 1,2,3,4,5

2 11,12,13,14,15

now to find values i am using query

sql = SELECT * FROM test12 WHERE `fid` LIKE ('%1%')

only problem in this query is it is selecting 1 and 11 and i require
only 1 as i am giving one in %1%
I assume this is MS SQL compatible SQL as it is not at all familiar to
me from an Access Jet point of view... I'll use the ANSI 92/99 approach
that you seem to be using, though I don't know what the delimiters here:
`fid` mean so will omit them.

Assuming there are no spaces and just comma delimiters, you could use a
brute force method which sets the criteria against a fid sandwiched
between two commas. I'm not sure how to do this in MS SQL syntax and I
am at home and don't have my MS SQL translation documents with me, but
the following is how you'd do it in Oracle (the double pipes are the
equivalent of "&" in VBA code and MS Jet SQL) :

SELECT *
FROM
test12
WHERE
',' || fid || ',' LIKE ('%,1,%')

In non-ANSI compliant Jet SQL, the above would be:

SELECT *
FROM
test12
WHERE
("," & fid & ",") LIKE ("*,1,*")

--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Whatcha doin?" - Ditto "TIM-MAY!!" - Me
Oct 16 '06 #3
Have the query place a comma at the beginning and end of your
field data, FID, then select based on ",1," not just "1". SQL follows:

SELECT ID, FID, "," & [fid] & "," AS FIDComma
FROM Data
WHERE ((("," & [fid] & ",") Like "*,1,*"));
Kevin C
"hardik" <ha**********@gmail.comwrote in message
news:11**********************@m7g2000cwm.googlegro ups.com...
hi friends i need help in this sql query

i have table like,

id fid
__ _____
autonumber text

and i am storing values like

id fid
___________________________________
1 1,2,3,4,5

2 11,12,13,14,15

now to find values i am using query

sql = SELECT * FROM test12 WHERE `fid` LIKE ('%1%')

only problem in this query is it is selecting 1 and 11 and i require
only 1 as i am giving one in %1%
now any one have answer of this question then plz plz tell me ........

Oct 16 '06 #4

"hardik" <ha**********@gmail.comwrote in message
news:11**********************@m7g2000cwm.googlegro ups.com...
hi friends i need help in this sql query

i have table like,

id fid
__ _____
autonumber text

and i am storing values like

id fid
___________________________________
1 1,2,3,4,5

2 11,12,13,14,15

now to find values i am using query

sql = SELECT * FROM test12 WHERE `fid` LIKE ('%1%')

only problem in this query is it is selecting 1 and 11 and i require
only 1 as i am giving one in %1%
now any one have answer of this question then plz plz tell me ........
Tim Marshall and Kc-Mass answered the question for your structure, But you
should really consider normalizing fid. I have come to regret using the same
structure in a menu system and option bill of material. Storing fid in a new
table, will make query much easier and quicker.

tblfid
ID fID
1 1
1 2
1 3
1 4
1 5
2 11
2 12
2 13
2 14
2 15

Oct 16 '06 #5

paii, Ron wrote:
"hardik" <ha**********@gmail.comwrote in message
news:11**********************@m7g2000cwm.googlegro ups.com...
hi friends i need help in this sql query

i have table like,

id fid
__ _____
autonumber text

and i am storing values like

id fid
___________________________________
1 1,2,3,4,5

2 11,12,13,14,15

now to find values i am using query

sql = SELECT * FROM test12 WHERE `fid` LIKE ('%1%')

only problem in this query is it is selecting 1 and 11 and i require
only 1 as i am giving one in %1%
now any one have answer of this question then plz plz tell me ........

Tim Marshall and Kc-Mass answered the question for your structure, But you
should really consider normalizing fid. I have come to regret using the same
structure in a menu system and option bill of material. Storing fid in a new
table, will make query much easier and quicker.

tblfid
ID fID
1 1
1 2
1 3
1 4
1 5
2 11
2 12
2 13
2 14
2 15

thanks paii but problem is solved and as in the normalization case real
tables are diffrent and data comes from diffrent tables i was just
giving sample for query . i am really thankful to all of you guys who
have help me that much.

thank you

Oct 16 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: BVM | last post by:
Hi, All: I have this error. It seems execution time is too long. Actually the execution time is about 30 seconds(I tested in Query analyzer). How do I solve this problem? ...
2
by: pratchaya | last post by:
This is my sample error in my MySQL Log New value of fp=(nil) failed sanity check, terminating stack trace! Please read http://www.mysql.com/doc/en/Using_stack_trace.html and follow instructions...
7
by: Patrick Fisher | last post by:
Hi I have a table which Contains entries with RefCode field containing INVP or INVPD Common fields in each entry would be InvoiceNo, Total and PurTyp for example. You could have ...
45
by: salad | last post by:
I'm curious about your opinion on setting relationships. When I designed my first app in Access I'd go to Tools/Relationships and set the relationships. Over time I'd go into the window and see...
8
by: vj | last post by:
Hi all, I want to solve the two equations u*tan(u)=w and u^2 + w^2=V^2, where V is a known constant, and u and w are the two unknowns to be determined. Please can someone suggest me how to...
1
by: arun | last post by:
Query is too complex -------------------------------------------------------------------------------- Hi, I was trying to solve this problem since last two days but couldn't find any solution. ...
4
by: hardik | last post by:
hi friends i need help in this sql query i have table like, id fid __ _____ autonumber text and i am storing values like
2
by: gsreenathreddy | last post by:
Hi! Please solve this query in employee table in scott user i would like view the details of all the employees (empno, ename )who are working under which manager(mgr) .with his manager name...
6
by: fido19 | last post by:
Once upon a time, there lived a chimpanzee called Luycha Bandor (aka Playboy Chimp). Luycha was unhappily married to Bunty Mona, a short but cute little lady chimp. Luycha was tall and handsome –...
0
by: xwebmaster | last post by:
Hi Please help me solving this query.. I have 3 tables.. comm_propDB ID | User_ID | mls_num -----|---------------|--------------------- 2 | 2 | 5004 3 | 2 ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.