473,385 Members | 1,930 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 3556
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',LEN(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',LEN(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
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...
5
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...
0
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
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...
125
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...
4
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...
27
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...
21
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...
2
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...

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.