bbholzbb
bbholzbb

Reputation: 1932

SQL selecting item with "begin with"/ putting a % behind a variable's name

I want to select all rows, where the column g_folder exists in the beginning of the search word. For example: One element in the table c_groups is '/f1' (in column g_folder). So I want to have only the items, which are in the beginning of the search word:

It should look like: g_folder% is like '/f1/xx'; But I can't put this percent behind a variable. How can I do this?

My statement:

   select count(*) from c_groups where g_folder is like '/f1/xx'

Upvotes: 2

Views: 217

Answers (1)

JNK
JNK

Reputation: 65187

If this is SQL Server, you can concatenate your column like so:

SELECT
  COUNT(*)
FROM
  c_groups
WHERE
  '/f1/xx' LIKE (g_folder + '%')

Upvotes: 2

Related Questions