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.

Priya Avanigadda46 reputationPosted Feb 15, 2015, 8:18 PM EST
Khargesh RajputRank #616 · 3.9K reputationPosted Feb 15, 2015, 8:50 PM EST
select * from student_table where name like "''+@name+'%'"
Joginder BangerRank #360 · 7K reputationPosted Feb 15, 2015, 9:19 PM EST
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.
umair mohsinRank #3,092 · 463 reputationPosted Feb 16, 2015, 5:04 AM EST
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.
umair mohsinRank #3,092 · 463 reputationPosted Feb 16, 2015, 5:08 AM EST
Joginder BangerRank #360 · 7K reputationPosted Feb 16, 2015, 6:20 AM EST
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
Jignesh TrivediRank #16 · 50.3K reputationPosted Feb 16, 2015, 6:38 PM EST
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.
Saumitr Sharma13 reputationPosted Feb 16, 2015, 7:57 PM EST
try this it will display the record that start with latter 'A'