Given one of the following strings (which represent a table/view name in SQL Server):
var x = "[my-Table.request]";
var x = "[dbo].[my-Table.request]";
var x = "dbo.[my-Table.request]";
I would like to get the table name (by C# code): my-Table.request
Any ideas? have i missed any possible representations here?
Quite simply via PARSENAME in TSQL:
PARSENAME(@x, 1)
With your edit where you want it in C#, you'd basically have to write it from scratch in C#, tokenizing by the ., [, ]. AFAIK there is no pre-canned implementation that does this for you.
If you're doing this on the SQL side, there's a PARSENAME function for doing exactly that.
E.g. PARSENAME(x,1) returns the object (in this case table) name. PARSENAME(x,2) returns the schema, etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With