i need select query for my data base. suppose i have 100 records in my database and i want to search records with a or b.
or any any other character.selection is done by textboxes i am writing this code
select * from student_table where name ="@name"
cmd.parameters.addwithvalue("@name",txtname.text);
now if i press s then records starts with s sholud display but not those records in which s is not the first word e.g.
sahil
siddharth
siddhu
rajesh
suraj
bhansali
rishab,james,kailash
suresh
i need a query to display records like sahil,siddhu,suraj ,siddharth,suresh not the other ones.
Saumitr SharmaPosted Feb 17, 2015, 12:57 AM
try this it will display the record that start with latter 'A'
Jignesh TrivediPosted Feb 16, 2015, 11:38 PM
Hi,
As explain above you can use LIKE operator....
Please refer below link to know more about LIKE
http://www.techonthenet.com/sql/like.php
http://beginner-sql-tutorial.com/sql-like-in-operators.htm
https://msdn.microsoft.com/en-us/library/ms179859.aspx
hope this will help you.
Joginder BangerPosted Feb 16, 2015, 11:20 AM
aadity
shail
jjkka
your query value is a
select * from tableName where columnName like "''+your query value+'%'" -- this query working only start with your query value.
output is aadity
select * from tablename where columnName like "'%'+@name+''" -- this query working only end with your query value.
output is jikka
select * from tablename where columnName like "'%'+@name+'%'" -- this query working match a your query value complete value.
output is
aadity
shail
jjkka
umair mohsinPosted Feb 16, 2015, 10:08 AM
umair mohsinPosted Feb 16, 2015, 10:04 AM
text boxes are there to find records it is not specifically the word starting with s. i need the query to display record as i directed to textboxes.
e.g: if a comes in aaditya and a also comes in sahil then, aaditya should display but not sahil.
Joginder BangerPosted Feb 16, 2015, 2:19 AM
your query is wrong because you want start with S but you are assign complete value. if you want records only start with S just changed your query like
select * from tableName where columnName like "''+your query value+'%'" -- this query working only start with your query value.
select * from tablename where columnName like "'%'+@name+''" -- this query working only end with your query value.
select * from tablename where columnName like "'%'+@name+'%'" -- this query working match a your query value complete value.
Khargesh RajputPosted Feb 16, 2015, 1:50 AM
select * from student_table where name like "''+@name+'%'"
Priya AvanigaddaPosted Feb 16, 2015, 1:18 AM