F Mckinnon
F Mckinnon

Reputation: 417

Specific String from SQL

I am currently making a program in c# that uses SQL queries. I am new to SQL and would like some help on a matter.

Is it possible for a specific position in a string to be queried?

Eg. SELECT ID FROM Names WHERE Firstname[0] = "J" AND Lastname = "Doe"

If anything is unclear please let me know, any help is appreciated, thank you.

Upvotes: 0

Views: 63

Answers (3)

Gordon Linoff
Gordon Linoff

Reputation: 1269563

Yes, you can, but rather like this

SELECT ID
FROM Names
WHERE Firstname LIKE 'J%' AND Lastname = 'Doe';

Notes:

  • In SQL, strings should be delimited with single quotes.
  • The LIKE operation has a pattern. The pattern says the first character is J; % is a wildcard that matches 0 or more characters.
  • Databases generally do not have a built-in array types that are compatible across databases. Further, no databases (as far as I know) , treats strings as arrays of characters. These concepts are somewhat foreign to SQL (although some databases do support arrays).

Upvotes: 1

user6775131
user6775131

Reputation: 31

You could use LIKE in WHERE clause.

example:-

SELECT ID FROM Names WHERE Firstname LIKE "J%" AND Lastname = "Doe"

Upvotes: 1

Shahrukh khan
Shahrukh khan

Reputation: 1

you can use keyword 'like' for example : WHERE names LIKE 'a%' it will return all name starting with character 'a'. like wise '%a'it will return all names ending with 'a'.

Upvotes: 0

Related Questions