Benji Taylor Benji Taylor - 1 year ago 60
SQL Question

Using filters and wildcards to find incorrect records on SQL server management studio

New to using SQL server management studio...

Just trying to filter my table results to show only records that have (deceased) in them...

So far I have

select SURNAME, count(SURNAME) from [dbo].[blahblah] group by SURNAME order by SURNAME

I would usually use
like the below, however it doesn't recognize these functions

select trim(translate(cast(GUAR_PHONE as string), '0123456789', ' ')),GUAR_PHONE
from atable
WHERE trim(translate(cast(GUAR_PHONE as string), '0123456789', ' '))<>'';

Answer Source

If you are looking for a string such as 'deceased', then you would use like:

select b.*
from dbo.blahblah b
where b.guar_phone like '%deceased%';

This seems to address the question at the beginning of the post. I have no idea what the code is supposed to be doing.

In SQL Server, if you just want to see if there are any non-numbers in the string, you would do:

where b.guar_phone like '%[^0-9]%'
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download