Question: In my SQL Server database there is scenario like database have one primary key and primary key is in format like '0000100001' and 'C100001'

I want to delete the all records from database which starts with '0' but not the records starts with 'C'.

I tried the inbuilt function `SUBSTRING('primary_key',1,1)='0'` but it did not helped me..
Thank You..

Answer: 
```
SUBSTRING('primary_key',1,1)='0' 

```

tests whether the **string literal** `"primary_key"` starts with the character `0` (which it doesn't so will return zero rows), Get rid of the single quotes to reference the column. (NB: If your column is not actually called `primary_key` you will need to reference its actual name of course!)

Or alternatively you can use `WHERE primary_key LIKE '0%'` which can use the index to locate the rows so is more efficient.
I don't know MS SQL, but in MySQL it would be something like this:

```
"DELETE * FROM your_table WHERE primary_key LIKE '0%' AND primary_key NOT LIKE 'C%'"

```

You can use the LIKE operator to essentially search for a occurances of either a string or a regular expression. It can take wildcards such as the `%` sign both in front, behind, or both in front and behind of the pattern you are looking for.

For example:

`LIKE 'C%'` would match anything starting with `C`

`LIKE '%C'` would match anything ending in `C`

`LIKE '[A-Z]%'` would match anything starting with a capital letter

`LIKE '%LOL%'` would match anything that has the word `LOL`(in caps) in it.

Further reading at
<http://msdn.microsoft.com/en-us/library/ms179859.aspx>