Skip to content

Instantly share code, notes, and snippets.

@royashbrook
Created February 25, 2018 00:05
Show Gist options
  • Select an option

  • Save royashbrook/7f86bfebe1b1ba5a2ea014a7802470a9 to your computer and use it in GitHub Desktop.

Select an option

Save royashbrook/7f86bfebe1b1ba5a2ea014a7802470a9 to your computer and use it in GitHub Desktop.
//meant to run in LINQPad
void Main() {
this.ExecuteCommand("set transaction isolation level read uncommitted");
string FindThis = "some text to find";
string q = @"
select
'[' + table_catalog + '].[' + table_schema + '].[' + table_name + ']' [t]
, '[' + column_name + ']' [c]
from
INFORMATION_SCHEMA.COLUMNS
where
data_type in ('nvarchar','nchar','varchar','char')
and character_maximum_length >= len({0})
";
string e = @"
select
case
when exists(
select *
from {0} with (nolock)
where {1} like '%{2}%'
)
then 1
else 0
end";
var matches = from a in this.ExecuteQuery<tc>(q,FindThis).Where (t =>
this.ExecuteQuery<int>(e.Replace("{0}",t.t).Replace("{1}",t.c).Replace("{2}",FindThis)
).Single().Equals(1)
) select a;
matches.Dump();
}
class tc {
public string t{get;set;}
public string c{get;set;}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment