8
Answers

need select query

Photo of umair mohsin

umair mohsin

10y
1k
1
  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.
 
 
 

Answers (8)

0
Photo of Saumitr Sharma
NA 38 869 10y
SELECT column name
  FROM table_name
 WHERE column name   LIKE 'A%'
try this it will display the record that start with latter 'A'
0
Photo of Jignesh Trivedi
NA 62.3k 46.3m 10y

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.

0
Photo of Joginder Banger
212 8.7k 1m 10y
suppose in table have three row in name column.

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

0
Photo of umair mohsin
969 405 74.6k 10y
what is the difference between 2nd one and the third one can you please elaborate with an example
0
Photo of umair mohsin
969 405 74.6k 10y
yes this is what i want. but if s comes with other names those names should not display.


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.
0
Photo of Joginder Banger
212 8.7k 1m 10y
Hi umair,
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.
0
Photo of Khargesh Rajput
311 5.6k 613k 10y
use like clause

select * from student_table where name like "''+@name+'%'"
0
Photo of Priya Avanigadda
NA 44 17.3k 10y
Hii, Do u want to display the names to start with "s" right??