2

How can I do this: select all rows WHERE a string filed start with a specific string like this (it's a command for SqlDataAdapter select command string in C#):

 SELECT * FROM mytable WHERE user_id = asd*

asd means all user_id filed that start with asd.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
hamze
  • 7,061
  • 6
  • 34
  • 43

2 Answers2

4

Use a LIKE statement such as:

SELECT * FROM mytable WHERE user_id LIKE 'asd%'

The % is a wild card, so that would work if you're looking for a string that starts with asd, otherwise, if you're just looking for asd anywhere in the string:

SELECT * FROM mytable WHERE user_id LIKE '%asd%'
kand
  • 2,268
  • 6
  • 31
  • 43
3

Try the following:

SELECT * FROM mytable WHERE user_id LIKE 'asd%'
Bernard
  • 7,908
  • 2
  • 36
  • 33