Rearrange the characters in a string alphabetically using SQL [closed] - sql

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I am looking to take a string field and rearrange the characters into alphabetical order. For example, if it was a name field and the name was MICHAEL SMITH it would change to ACEHHIILMMST.
The main purpose is to look for duplicates in a field like name where someone could have made a typo and put in the name as MICHEAL SMITH or MICHAEL SMTIH. Another option I thought of would be to assign a number value to each letter (1-26) and then if the sum of those values and the length of the name field are the same it would be considered a duplicate. Problem with that is I do not know how to sum up numbers in a string field.
Also, I am using Oracle SQL so the functions would be based on those available.
Any ideas or at least places to start?
EDIT
I am not trying to ask for the code for how to do this, I am asking more if it is possible or not and if possible, what would my starting place be (types of functions, techniques, etc)

Check utl_match. It can be used to measure the similarity of two strings.
select utl_match.edit_distance_similarity('MICHAEL SMITH','MICHEAL SMITH') from dual
85
select utl_match.edit_distance_similarity('MICHAEL SMITH','MICHELLE SMITH') from dual
79
select utl_match.edit_distance_similarity('MICHAEL SMITH','FRANKIE JONES') from dual
8

Related

SQL LIKE doesn't find obvious matches [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I'm writing the following SQL query:
SELECT *
FROM OS
WHERE OS.VERSION LIKE '%1%';
In my table there are rows with char 1 in it. However, it returns an empty result.
I changed a little bit the LIKE clause to different values, but it still doesn't work.
What can I do to fix that?
Try double-quotes and * for wildcards. You are using Oracle syntax instead of Access syntax.
LIKE operation can't be used with columns of integer type. I assume that OS.Version is of integer type?
Edit1:
If you are referring to MS Access then you have to do the LIKE with stars (*) instead of %.

Is there a way to remove specific characters from SQL Server Column [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I have a database table that contains a column for pricing.
Its very old, so it was written before i understood datatypes. so we are using varchar for a money value.
Ive noticed some columns have $ in them, so what I'm wondering is... is there a way with SQL Server to perform an update of the table and remove any instances of non numeric characters or at the very least remove the $ from the string in the columns in one go ?
I hope this is possible.
Update tbl
SET price = replace(price, '$', '')
Here is the replace definition

VBA cell referencing and random numbers [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I was having a play around with excel 2007 VBA and was hoping to create a Macro that generates a random number, then outputs a string based on the number generated. For example,
Number String
1 A
2 B
3 C
4 D
If the random number is 4, the output would be D.
I have a table of a similar nature in my Excel worksheet.
So far I have not had much success at doing this, any thoughts?
If all you need is to generate A - Z with equal probability then use =CHAR(65 + RAND()*26) directly on the worksheet.
It's always better to keep away from VBA as it makes spreadsheets more difficult to debug and since VBA works in a single thread, these days it can be a bottleneck.
Another way on worksheet, to deal with any string is to use
=CHOOSE(rand() * 4 + 1, "One", "Of", "Four", "Strings")
If you have a table as you say then you can use INDEX, e.g. if List is a named range containing a list of strings in separate cells you can use this formula to get a string at random
=INDEX(List,1+RAND()*COUNTA(List))

Sql databases select command [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 8 years ago.
Improve this question
I am new to databases. And our teacher gave us pretty hard assignment. There are two tables. First table nickname is abilities(of superhero's:) ) and second table name superheros.
We have to select nick of Superhero and his average(medial) range for those who has two abilities?
Image of both tables:
Original here: http://postimg.org/image/85pqbc47n/
I will not give you solution - after all, it's homework and you have to learn something :) But I can give you an advice - try to do one task at a time
first, find those superheroes who has only 2 abilities (actually, you can do this by quering only table with abilities)
second - try to find average range of abilities for all superheroes (here you'll need join)
combine your queries
take a look at join, group by, count and having
Don't feel bad if you can't write it at first attempt, your query is not super easy, but 'm sure you can do this.
You can use HAVING and AVG() for this:
SELECT s.NickName, AVG(a.Range)
FROM abilities a
JOIN superhero s
ON a.ID_SuperHero = s.ID_SuperHero
GROUP BY s.NickName
HAVING COUNT(DISTINCT a.Abilities > 1)

Overcoming the reserved word "IN" in sql server [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
Just for reference I am using SQL Azure.
I noticed when I am trying to select data from a table based on a license plate and the state of that plate I get no results back if the state is "IN". I realize the word "IN" is reserved in SQL server; however, I am containing that within quotes in my query. I currently am in testing phase and have only one record in the table which has a lisence plate 287YGB and state IN.
If I write my query as follows I get nothing back.
SELECT MakeModel, CitizenID, VehicleID FROM tblVehicles WHERE tblVehicles.Lisence = '287YGB' AND tblVehicles.PlateState = 'IN'
If I write my query this way I get back my result. But this is not good enough.
SELECT MakeModel, CitizenID, VehicleID FROM tblVehicles WHERE tblVehicles.Lisence = '287YGB'
And finally, if I write my query this way I get the only row in the table.
SELECT MakeModel, CitizenID, VehicleID FROM tblVehicles
From these tests I can see that the last where parameter is causing the problem. I am assuming it is due to the fact that the word "IN" is reserved. Is there a way around this?
Reserved words usually only cause problems if you're using them as field names, and in that case you need to wrap them with brackets ("[]") to eliminate the problem. I will amost guarantee you that your PlateState has some garbage in it, so you need to either trim it first (LTRIM(RTRIM(PlateState)) = 'IN') or use Like '%IN%' instead, and this will return the results you expect.
try this
SELECT MakeModel, CitizenID, VehicleID FROM tblVehicles WHERE tblVehicles.Lisence = '287YGB' AND LTRIM(RTRIM(tblVehicles.PlateState)) = 'IN'