Click here to Skip to main content
15,886,026 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi
I have the table like this

ID       name1               age
1      aaa,bbb,ccc         20,30,40

if i query using 'aaa' mean i want to get 20,bbb mean 30 ,ccc means 40


Any suggestions pls...........
Posted

1 solution

That is a poor database design: you can do it - it's not at all simple, but you can do it - but it's just not a good use of resources.
Instead, separate your Name1 and age columns into separate columns, given them proper datatypes, so your numeric values are stored in numeric fields, and do it that way:

ID Name1 Age
1  aaa   20
1  bbb   30
1  ccc   40
It will make your life a lot, lot simpler in the long run!

And BTW: you probably don't want to store "Age" as a number: it's a moving value depending on the required date. Instead, you would be better using a DateTime column, and storing the Birthdate instead - that way the Age can be easily worked out and is always correct...
 
Share this answer
 
Comments
prabhatsp 7-Feb-14 4:53am    
thank You for Your response, but i want to do this in that way only, any method or way to do that
OriginalGriff 7-Feb-14 5:53am    
As I said, you can - but it is very complex: you will have to create a temporary table and fill the rows from the two column values, because SQL string handling is pretty limited. You can then return the matching rows from the table. Slow, memory hungry, and a massive waste of resources.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900