(basically im trying to remove leading zeroz from a phone number , becuase our SMS provider requires it. Sure I can do it in C# , but i'd like sql to do that)
patindex doesn't find a non-0 character in 0. When there's no match, the function returns 0. And if substring takes 0 as the starting position, it peculiarly treats it as position 0 of the source string.
In case of an all-0 string (or an empty string), the result will be an index beyond the last character of the source, but that's fine, substring handles that well.
Hey guys, I just need to confirm something quickly - say I have a table with 3 columns - A, B and C, and create a view on that table, which has the same columns - A, B and C, plus one column D which is calculated based on columns B and C. Is there any method to change the value in view.D for a given record without altering the original values in columns of the physical table?
@ROAL What do you mean by "change the value in view.D for a given record"? A view isn't really a table, it's just a query. Whatever values it returns are not really stored somewhere so that you could change them.
And while you can write to view.A, view.B or view.C because there are actual table columns behind those, you can't write to view.D, because that's a calculated column.
Yeah, that's what I thought, @AndriyM , @wBob. Thanks for the tip. This is mostly a question of how to overcome the limitations of a proprietary software sold by a company that mostly refuses to do anything that they don't consider "standard".
@AndriyM the software uses our own SQL server, so we have full control over the database, however, I'd like to avoid tampering with the actual tables. The company went on a little rage fest even over adding a new column to the view (while the software handles this nicely, as the columns that get selected are actually chosen by each user).
@ROAL I don't see how you would need a trigger. Unless you mean creating a row in the new table for each row of the "main" table (which I so far think is unnecessary, but maybe it has to do with something you haven't told us).
But in any event, if you already know how to solve your problem, that's what really matters.
@Darth_Wardy There's quite a good reason for SQL's limited regex capabilities, and that's because you can't convert a regex into a sarg-able search. Ordinary wildcards can be sarg-able in some circumstances (where you have a prefix). Regex searches will necessitate a table scan or other O(n) operation.
The answer is no, not in the general case, although it might depend on what you mean by efficient. For these purposes, I'll use the following definition: 'Makes effective use of indexes and joins in a sensible order' which is probably as good as any.
In this case, 'Efficient' queries are 's-arg...
The short answer is 'No.' There is no index structure currently available on any DBMS platform that will index partial matches of a regex like this.
The long answer is that a leading constant on a wildcard match (e.g. 'foo_') can be used as a prefix for index matches. Many DBMS platforms wil...
Having said that, there's no intrinsic reason why it couldn't support regex matching, although the inefficiencies above will always come into play.
This is basicaly something I am facing for couple of months. Sometimes when I try to add comment to a question or answer or try to vote question I get error
An Error Occurred-Please Retry your Request
Below is screenshot of what I am referring to. I was trying to vote up on question and go...
@TomV It's probably not a good look, but on balance I don't feel minded to edit the profile to remove it. If you wanted to gauge how the community feels about it, you could ask a general question about the broad issue - links in profiles - and see what people say.
Hi, welcome to the site. Please don't overdo the bold and the font size, it makes this question unreadable. OK maybe not unreadable, but it doesn't incite effort from someone trying to parse it. Proper formatting does. — Tom V51 secs ago
My ignorance of the statistics has come back to bite me since I picked up an Azure SQL DW project, and DW doesn't auto update statistics. Anyone recommend a good beginner's guide to statistics? Web or book or other is fine.
I'll answer in two parts: first "why the traditional answer about separating sequential and random often doesn't apply."
Then I'll discuss the potential benefits of separating files at the Windows physicaldisk, and to adding additional vHBAs and distributing the physicaldisks among them.
Expect...
@mmarie I did a project with this interesting and powerful product last Christmas. The JRJ stuff is golden on this, and honestly there isn't a great deal more documentation other than that and the Azure docs online.
There is some obvious stuff you need to know like you can't use MERGE, other limited T-SQL surface area, learn how to use CTAS, Polybase is very fast for getting data in, SSIS not so much, we didn't get round to using Azure Data Factory.
There is a migration wizard which is worth running - here's some sample output which is really instructive as to what you can and can't do. The new July 2016 version of SSMS supports Azure SQL Datawarehouse now, so that's nice : )
The output from EXPLAIN your_query is interesting to look at and if you can learn the difference between round robin and hash distributed tables, you're well on your way.
@TomV Yes, glad to see @sql_handle from Twitter here
@wBob Yes I think JRJ's job is basically to help people understand how to use Azure SQL DW. Would think he'd answer a question about managing stats if asked.
@JamesLupolt Pretty sure I've seen some code to automate ADW stats build somewhere.
@mmarie There is a really really awful book by TeraTom purportedly about Azure SQL Data Warehouse, but avoid like the plague. This book is practically a crime.
[shuffles awkwardly as TeraTom enters the room]. I hi TeraTom, didn't see you there...