How to check if parts of a string match to a column data in sql table - sql

I want to write a query which checks the input provided by the user with the column data of my table. i tried using LIKE and CONTAINS but it didnt work for me. eg my table data contains "Bar B Q Tonight" and if user enters "BBQ Tonight", how to deal with it? I have enabled full text-indexing for my table too. I am working on sql server 2005 in visual studio. can anybody guide me?

One approach to deal with is to create separate column on your table which will contain popular search tags or keywords, based on that you can show the results to the user.

Synonyms and acronyms are a challenge for information retrieval systems (IR).
Perhaps implement a tiny Acronym Expansion System. Acronyms and expanded terms.
When a user enters such words you need to provide a few suggestions or expanded terms. Like in Google do suggestions or you can show couple of similar terms in return for the query and let the user decide which is relevant.
you need minimum three table as I envisage it but depends on context.
one table contains stop words so you parse each word in the
entered phrase and remove all stop words.
then search individual term in acronyms table and if an
acronym has more than one definitions you can substitute acronym
for each definition and pass it back to user asking which is
relevant. if this is web environment it means list of hyperlinks.

Related

RSA - Archer - Hide multiple fields in a search result

When performing a search in Archer, the result contains some un-necessary fields. Is there a way to show only fields that belong to Application "General information" ? In other words, there are some fields that are suggested to being added to "General Information" tab which appear in a search result.
I know I can disable these fields by selecting the field, then clicking on "modify field properties", "options" and untick the show field in a search result.
Since I have multiple applications and a lot of fields, doing this will take a lot of time. Is there any script or trick to hide all these fields in a search result?
You could always use the API and create your own search XML to contain only the fields you want to see.
But short of doing that, I think you've hit the nail on the head. You'll need to go into each application and then modify each of the fields you don't want shown. I don't think it's a waste of time, as you're surely not changing this search result every time... it's a one time deal and if it makes it easier for you or the end users, it's certainly worth it IMO.
If you have access to the database then you can modify table "fielddef" and make fields not searchable by default. You can join "fielddef" table with "level" and "moduletranslation" and target only specific modules this way.
I don't have the SQL code for this since I didn't have to make a bulk update to the fields and make them not searchable.
It should take 5 min to join these 3 tables and make an update if you are good with SQL.

How can I search the entire SQL database for a specific column name, and then search only those columns for a specific value?

At work, we use an absolutely massive database with multiple different programs writing to the main bucket. Unfortunately, there's not always a good way to know from those individual programs where specific data points might be written to the database. I have a query that can search everything for a specific value or string, but because of the size of the database, it usually takes about 7 hours to complete.
I thought that if I could narrow the search a bit, I might be able to speed that up. A lot of the values I often have to look up would be under similarly named columns (i.e. "UserName", "UserID", etc.) Is there a good way to do a search that looks through all of my tables for a specific column name, and then searches only those columns for the value that I'm trying to locate?
I found a similar question asked a few years back
Search sql database for a column name, then search for a value within the retuned columns
but when I run the answer, all it returns is "Command(s) completed successfully."
I'm still a little green at this, so I'm not discounting the fact that it could be a PICNIC issue on my end.

Database Search that Compares Results for Mutiple Seach Keywords

Fist, let me say I know very little about SQL language and am trying to learn (albeit very slowly). I have created a database table with columns for
ECOREGION_ID
ECOREGION_NAME
SPECIES_NAME
CLASS
so that there is one row for each species name in each ecoregion. My end goal is to create a form in which I can enter in multiple species names and search for the ecoregions they share. For example, if I enter into the 4 different search boxes "Tiger", "Red Panda", "Sloth Bear", and "Rhino" it would bring up a list of all the Ecoregions in which these four species share. I am wondering a few things:
Is my data set up in the correct way in order to do this or is there a more efficient way to set i t up?
What statement should I use to create an sql statement to perform the search I want?
What is the technical term for what I am wanting to do? I have tried many different searches on different forums and can't seem to find what I am looking for, mostly because I probably don't know what to search, lol.
Thanks,
-Drew
You have ECORegion_ID and ECORegion_Name in the same table. I would suggest create a separate table to hold ECORegions. This table would have both an ID and Name. The search table would then only have the ECORegion_ID. This process is called normalization. It basically reduces redundant data in your database.
You are looking for a SELECT statement, which is used to pull data out of one or more tables. The statement has a WHERE option to restrict which rows you bring back and an IN expression as part of the WHERE to allow you to look for multiple keywords.
Search for Normalization to see why to put region name in a separate table. Look up SQL Select to get syntax for the select statement you should get off to a good start

Access 2010 Database Clenup

I have problems with my records within my database, so I have a template with about 260,000 records and for each record they have 3 identification columns to determine what time period the record is from and location: one for year, one for month, and one for region. Then the information for identifying the specific item is TagName, and Description. The Problem I am having is when someone entered data into this database they entered different description for the same device, I know this because the tag name is the same. Can I write code that will go through the data base find the items with the same tag name and use one of the descriptions to replace the ones that are different to have a more uniform database. Also some devices do not have tag names so we would want to avoid the "" Case.
Also moving forward into the future I have added more columns to the database to allow for more information to be retrieved, is there a way that I can back fill the data to older records once I know that they have the same tag name and Description once the database is cleaned up? Thanks in advance for the information it is much appreciated.
I assume that this will have to be done with VBA of some sort to modify records by looking for the first record with that description and using a variable to assign that description to all the other items with the same tag name? I just am not sure of the correct VBA syntax to go about this. I assume a similar method would be used for the backfilling process?
Your question is rather broad and multifaceted, so I'll answer key parts in steps:
The Problem I am having is when someone entered data into this
database they entered different description for the same device, I
know this because the tag name is the same.
While you could fix up those inconsistencies easily enough with a bit of SQL code, it would be better to avoid those inconsistencies being possible in the first place:
Create a new table, let's call it 'Tags', with TagName and TagDescription fields, and with TagName set as the primary key. Ensure both fields have their Required setting to True and Allow Zero Length to False.
Populate this new table with all possible tags - you can do this with a one-off 'append query' in Access jargon (INSERT INTO statement in SQL).
Delete the tag description column from the main table.
Go into the Relationships view and add a one-to-many relation between the two tables, linking the TagName field in the main table to the TagName field in the Tags table.
As required, create a query that aggregates data from the two tables.
Also some devices do not have tag names so we would want to avoid the
"" Case.
In Access, the concept of an empty string ("") is different from the concept of a true blank or 'null'. As such, it would be a good idea to replace all empty strings (if there are any) with nulls -
UPDATE MyTable SET TagName = Null WHERE TagName = '';
You can then set the TagName field's Allow Zero Length property to False in the table designer.
Also moving forward into the future I have added more columns to the
database to allow for more information to be retrieved
Think less in terms of more columns than more tables.
I assume that this will have to be done with VBA of some sort to modify records
Either VBA, SQL, or the Access query designers (which create SQL code behind the scenes). In terms of being able to crunch through data the quickest, SQL is best, though pure VBA (and in particular, using the DAO object library) can be easier to understand and follow.

Get column name & table name from value

Actually I have a new client & their Database has no standard naming conventions & the application is in classic asp.I have a form in which a form there are many values in the different textboxes, it it very difficult to trace the value come from which table.& also there is no erd.
I need a query from which I can get the table name with column name by giving Value.
Let's suppose I have a value having label name abc#= '6599912268'
& the new project has no ERD no standard of naming conventions... I need a fast way to know the abc# ='6599912268' is taking from which table & which column name.... like this the UI has many values which is time taken to trace manually
Is there any way to trace it?
The simple answer is no. There is no way to trace table/column it comes from by mere inspection of the value.
I suggest the following.
Find out what type of db your product is using. Where it is situatede, do you have access to it.
If you have access to the database, get to know the db structure. What each table is meant to store, the relationships etc. Speak to the db administrator or the business analayst to increase your knowledge on the product domain.
Once you have the db structure, try and compare the table to the page. Eg. The user details will most like be stored in a db table named 'Users' or 'Membership' Catch my drift?
Then have a look at the web sites source code. Look at the specific page you are at. Is the sql code embedded in the source code (asp page) or does it call a COM server or something similar? If you are "lucky" (and I say lucky for on the purpose of your problem that you are having) you fill find the sql code in the asp page.
If it calls a COM object or something similar, then you will have to dig up the source code for that, and that is most likely where you sql will reside.
There is no easy way to do this, you have to use a stored procedure to loop over all the tables in the database and search for the value, and it will probably take a while.
There's a stored procedure and examples here: Search all columns in all the tables in a database for a specific value. You'll see there are stored procedures for finding dates, strings, numbers.
Not possible, and If you search the column with the value, there is a possible chance that you get multiple columns with the same value, so how would you differentiate them and the same case is for the table.