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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 returning exact row

Author  Topic 

namitjung
Starting Member

10 Posts

Posted - 2006-06-26 : 08:44:44
Hi All,

I am trying to return the exact matching row from sql in asp.The column type is varchar so i use wild char characters to return the row but it didn't work.I also tried to use IN statement in sql but it also didn't work.

I would like to explain the problem scenario as follows:


TableName: users

userid username useremail matchtypes
1 Bob bob@mail.com 1,4,5,13
2 Jessica jes@mail.com 3,21,45,67
3 Ken ke@mail.com 13,42,12
4 Stephe ste@mai.com 103,24,203
5 Andrew and@mail.com 3,12,45


I am creating dating site,so whenever a match is found it should send email to the respective user. In matchtypes column, matchid are inserted as text.i got problem to extract the exact match records.let's say we have to extract those records which should match with 3. For that I used following sql statement


select * from users where matchtypes like '%3%'

but sql returns all records since there is 3 in every row. But i want it to extract only two records (Jessica and andrew) since they have exact match .

Is thery any sql statement which i can use to extract the exact records.

Thanx in advance

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-06-26 : 08:47:30
[code]select * from users where ',' + matchtypes + ',' like '%,3,%'[/code]
Peter Larsson
Helsingborg, Sweden
Go to Top of Page

namitjung
Starting Member

10 Posts

Posted - 2006-06-26 : 08:51:48
thanx a lot i think it must work..

but i didn't get after where "," + matchtypes + "," . Is it column name?
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-06-26 : 08:54:53
No, the ',' puts commas before and after your column MatchTypes, in case that the wanted MatchType is first or last in the csv list.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

namitjung
Starting Member

10 Posts

Posted - 2006-06-26 : 08:58:13
Thank you very much....

My problem is solved...

Thank you again.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-06-26 : 09:02:55
Read about Normalisation
http://www.datamodel.org/NormalizationRules.html

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -