473,811 Members | 3,314 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Checking for transposed numbers

Does anyone have a UDF or Stored Procedure that checks for transposed
numbers in a group?
Jul 20 '05 #1
2 3577
Scott Levine from Atlanta?

Here's an example that might help, depending on your exact definition of
"transposed ". This query finds rows with exactly the same digits in any
order.

CREATE TABLE SomeTable (x INTEGER NOT NULL)
/* Sample data */
INSERT INTO SomeTable (x) VALUES (3412)
INSERT INTO SomeTable (x) VALUES (4567)
INSERT INTO SomeTable (x) VALUES (4321)

SELECT T1.x
FROM SomeTable AS T1
JOIN SomeTable AS T2
ON
REPLICATE('0',L EN(T1.x)-LEN(REPLACE(T1. x,'0','')))
+REPLICATE('1', LEN(T1.x)-LEN(REPLACE(T1. x,'1','')))
+REPLICATE('2', LEN(T1.x)-LEN(REPLACE(T1. x,'2','')))
+REPLICATE('3', LEN(T1.x)-LEN(REPLACE(T1. x,'3','')))
+REPLICATE('4', LEN(T1.x)-LEN(REPLACE(T1. x,'4','')))
+REPLICATE('5', LEN(T1.x)-LEN(REPLACE(T1. x,'5','')))
+REPLICATE('6', LEN(T1.x)-LEN(REPLACE(T1. x,'6','')))
+REPLICATE('7', LEN(T1.x)-LEN(REPLACE(T1. x,'7','')))
+REPLICATE('8', LEN(T1.x)-LEN(REPLACE(T1. x,'8','')))
+REPLICATE('9', LEN(T1.x)-LEN(REPLACE(T1. x,'9','')))
=
REPLICATE('0',L EN(T2.x)-LEN(REPLACE(T2. x,'0','')))
+REPLICATE('1', LEN(T2.x)-LEN(REPLACE(T2. x,'1','')))
+REPLICATE('2', LEN(T2.x)-LEN(REPLACE(T2. x,'2','')))
+REPLICATE('3', LEN(T2.x)-LEN(REPLACE(T2. x,'3','')))
+REPLICATE('4', LEN(T2.x)-LEN(REPLACE(T2. x,'4','')))
+REPLICATE('5', LEN(T2.x)-LEN(REPLACE(T2. x,'5','')))
+REPLICATE('6', LEN(T2.x)-LEN(REPLACE(T2. x,'6','')))
+REPLICATE('7', LEN(T2.x)-LEN(REPLACE(T2. x,'7','')))
+REPLICATE('8', LEN(T2.x)-LEN(REPLACE(T2. x,'8','')))
+REPLICATE('9', LEN(T2.x)-LEN(REPLACE(T2. x,'9','')))
AND T1.x<>T2.x
--
David Portas
SQL Server MVP
--
Jul 20 '05 #2
>> Does anyone have a UDF or Stored Procedure that checks for
transposed numbers in a group? <<

Can we get a better spec and sample data? Numbers are not transposed;
They are abstractions which do not have an ordering. Letters and
Numerals can be transposed. There are pairwise and disjoint
transposes; do you care what kind of transpose? Is there a maximum
length?

Short strings can be done with a table look up, which will be in
parallel as a JOIN and much faster than a proprietary UDF.
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
3639
by: JJA | last post by:
I would like some advice on a data and query problem I face. I have a data table with a "raw key" value which is not guaranteed to be valid at its source. Normally, this value will be 9 numeric digits and map to a "names" table where the entity is given assigned an "official name". My problem is that I'd like to be able to identify data values that are "close" to being "correct". For example, in the case of a nine digit number such as...
5
11094
by: William Payne | last post by:
Hello, I am in the process of converting a C++ program to a C program. The user of the program is supposed to supply an integer on the command line and in the C++ version of the program I was using something called stringstreams to do the conversion. Here's my C version, can I leave it as it is or does it need to be robustified or changed in any manner, regarding error checking? char* endptr; errno = 0;
0
1073
by: Roger | last post by:
I have a datagrid showing the following.... 3114 BUF 3/25/2005 A 3114 BUF 3/24/2005 A 3114 BUF 3/23/2005 B .. I have transposed this to Site Ext 3/25/2005 3/24/2005 3/23/2005 3114 Buf A A C
3
3706
by: LSW | last post by:
I'm using Borland Turbo C++ 3.0 to develop an embedded system to shift data around a network. At the moment we receive a string of bytes over a serial line and reassemble them into floating point values. If the bytes are not assembled correctly then it's possible to produce some floating point values that aren't 'genuine' numbers. Does anyone have any suggestions on how to check a float/double is valid (i.e. checking for NANs, infinity...
125
6629
by: jacob navia | last post by:
We hear very often in this discussion group that bounds checking, or safety tests are too expensive to be used in C. Several researchers of UCSD have published an interesting paper about this problem. http://www.jilp.org/vol9/v9paper10.pdf Specifically, they measured the overhead of a bounds
4
7924
by: H.S. | last post by:
Hello, I am trying out a few methods with which to test of a given number is practically zero. as an example, does the following test correctly if a given number is zero within machine precision? I am trying out this method to check for a practical zero in an algorithm I am implementing in C++. ------------------------- #include <iostream> #include <iomanip>
27
2299
by: Aaron Hsu | last post by:
Hey all, After seeing the Secure version I/O functions thread, it occured to me that maybe not everyone agrees with the almost universal adage that I have heard. I have Always been told that using things like strlcpy and other explicitly bounded functions were better than using the non-bounded versions like strcpy. Is this a matter of good programming style, or is this just needless overhead?
21
11383
by: ningxin | last post by:
Hi, i am currently taking a module in c++ in the university, and was given an assignment. because i have no prior background on the subject, everything is kind of new to me. i have tried for quite some time and still not able to get the solution out. so i hope you guys can help me out. of course i am not expecting a full solution, but i would greatly appreciate it if anyone can suggest to me what should i do. i am very new to this subject so...
2
1954
by: jelena1290 | last post by:
Hi, I desperately need help here.... I have 2 tables to start with: Table1: Data_2009 ID filiale product plan fakt 10 filiale 4 product 1 3 filiale 3 product 1 2 filiale 2 product 1
0
9605
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10651
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10393
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10405
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9208
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6893
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5697
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4342
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3871
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.