![]() ![]() ![]() If it matches, it means string consist of repeating characters. What i do is take x number of characters from a string, and then trying to replicate these characters so they fill the string and trying to compare to the initial string. It’s easy to learn, has just a few easy-to-understand tables, and has real-world data distributions for numbers, dates, and strings. SELECT SUBSTRING(nString, 1, x.x) AS actual Stack Overflow 149 I use a Microsoft SQL Server version of the public Stack Overflow data export for my blog posts and training classes because it’s way more interesting than a lot of sample data sets out there. , CASE WHEN actual = nString THEN 0 ELSE 1 END DESC ORDER BY CASE WHEN REPLICATE(actual, LEN(nString) / z.x) = nString THEN 1 ELSE 0 END DESC Here's another version: DECLARE TABLE (n int, expected int) IIF(NumberOfDigits % 5 = 0, 1, 0) As HasFiveParts) As LengthDividers ![]() You can choose between locally redundant storage (LRS), zone-redundant storage (ZRS), geo-redundant storage (GRS), or read-access geo-redundant storage (RA-GRS). IIF(NumberOfDigits % 3 = 0, 1, 0) As HasThreeParts, 1 Answer Sorted by: 0 Based on the Azure SQL Managed Instance pricing page, the Backup Storage Tier is the type of storage used for storing automated backups of your databases. SELECT IIF(NumberOfDigits % 2 = 0, 1, 0) As HasTwoParts, Then, the query: I've had to use quite a few CROSS APPLYs and a CASE expression, but it does provide the expected result: SELECT col, expected,ĪND LEFT(StringCol, NumberOfDigits/2) = RIGHT(StringCol, NumberOfDigits/2) THEN LEFT(StringCol, NumberOfDigits/2)ĪND LEFT(StringCol, NumberOfDigits/3) = RIGHT(StringCol, NumberOfDigits/3)ĪND LEFT(StringCol, NumberOfDigits/3) = SUBSTRING(StringCol, (NumberOfDigits/3)+1, (NumberOfDigits/3)) THEN LEFT(StringCol, NumberOfDigits/3)ĪND LEFT(StringCol, NumberOfDigits/5) = RIGHT(StringCol, NumberOfDigits/5) THEN LEFT(StringCol, NumberOfDigits/5)įROM APPLY (SELECT CAST(col as varchar(12)) As StringCol) As AsStringĬROSS APPLY (SELECT LEN(StringCol) As NumberOfDigits) As Length Note the comments - they specify why the expected result is what it is. (BTW, with regards to Thom A's comment (expected result from 111111), it returns 111)įirst, create and populate sample table ( Please save us this step in your future questions): DECLARE AS TABLE My solution is quite cumbersome but it works for all the scenarios you've described and a few scenarios I came up with based on your question. 2 Answers Sorted by: 0 trying to get the sql to identify the data from TAB1 which dont have corresponding data in Tab2 To me, that looks like a candidate for the minus set operator. Well, string manipulation isn't T-SQL's strong suit, but I was curious as to how hard will it be to find a pure T-SQL solution for this. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |