473,378 Members | 1,536 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,378 software developers and data experts.

Table Loop and New Column in the same Table

Table 1
ID Title Object 1
1 Book 1 Home Alone
2 Book 2 Forest Gump
3 Book 3 James Bond

Goal is to loop thru the table and use an if statement to rename the Object 1 and create a field (New) on the table.

If Book 1 is Like “*Home”, then Children’s book
Book 2 is like “*Forest” , then Horror book

Final Output

Table 1

ID Title Object 1 New Field
1 Book1 Home Alone Children’s book
2 Book2 Forest Gump Horror book
Jun 12 '16 #1

✓ answered by PhilOfWalton

I think you're on a hiding to nothing.
How many Key words are you going to search for (probably not many fewer than the number of book titles)?
How are you going to deal with a book title like "My home in the forest"?

I know it's not what you want to hear, but I would create a table of book types,
Expand|Select|Wrap|Line Numbers
  1. TblBookTypes
  2.    BookTypeID      Autonumber
  3.    BookType        No Duplicates
  4.  
Include BookTypeID in your book table, and have a combo box to manually assign the book type to each book.

Phil

4 875
PhilOfWalton
1,430 Expert 1GB
I think you're on a hiding to nothing.
How many Key words are you going to search for (probably not many fewer than the number of book titles)?
How are you going to deal with a book title like "My home in the forest"?

I know it's not what you want to hear, but I would create a table of book types,
Expand|Select|Wrap|Line Numbers
  1. TblBookTypes
  2.    BookTypeID      Autonumber
  3.    BookType        No Duplicates
  4.  
Include BookTypeID in your book table, and have a combo box to manually assign the book type to each book.

Phil
Jun 12 '16 #2
nico5038
3,080 Expert 2GB
I concur with Phil, typing Titles automatically will never be 100% accurate.
You could use an update statement to set the Type field initially, but the downside is that overlooking a wrong type between hundreds of entries will be harder as typing them manually. Thus many applications use a table as described by Phil and let the user select the type. Don't forget to add a type "Other" or allow new types to be added.

Nic;o)
Jun 12 '16 #3
PhilOfWalton
1,430 Expert 1GB
Actually, thinking further, the more titles there are, the more keywords are needed to prevent the type being "Other".

The more keywords there are, the more often there are going to be 2 or 3 or more keywords in a title.

Next problem is how do you create the keyword table? Only by manually reading the titles and manually selecting the keyword and adding it to the table.

Don't get me wrong, what you want to do is very easy but the results will be so inaccurate that it's not worth the effort.

In the example of "My home in the Forest", we could easily set that to Children's book as it found the word "Home"

If the title was "The Forest's my home", then the classification would be horror.

Phil
Jun 12 '16 #4
zmbd
5,501 Expert Mod 4TB
I concur...
also there is the issue of proper normalization to consider.
Jun 12 '16 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: me | last post by:
I would like to add an Identity to an existing column in a table using a stored procedure then add records to the table and then remove the identity after the records have been added or something...
11
by: Peter Foti | last post by:
Hi all, I have a form that contains a 2 column table. In the left column is the description for a particular input (ie - "First Name", "Last Name", "Phone Number", etc.). In the right column...
3
by: Prince Kumar | last post by:
Is there any way I can define an Unique constraint or unique index which allows more than one null values for the same column combination in DB2? ie, If my index is defined on (col3, col4) where...
1
by: p175 | last post by:
People, I have the following table and I need to add a column that uses a the listed UDF to count the number of days within specific quarters by year. CREATE TABLE HISTORY_MB (...
5
by: Mike L | last post by:
Hello all I'm trying to migrate a BE from Access to SQL Server. I've been making changes to the Access BE from the FE with SQL statements, and want to do the same with the BE in SQL Server. ...
5
by: Hymer | last post by:
Hello, I have a small two-column table with three rows. The first column has a logo and the second column has the name of the organization. The logo's in the first column are too high. That...
3
by: Gregor KovaĨ | last post by:
Hi! I have a table with a column of BIGINT and I want to change the type to SMALLINT. Command ALTER TABLE TABLE1 ALTER COLUMN COL1 SET DATA TYPE SMALLINT does not work since I cannot specify...
1
by: lcourchesne | last post by:
Hi there, This is what I am trying to do: Create a query that will insert a column from Table 2 into Table 1. These two tables are exactly the same in structure, however, there is no unique...
3
by: Csaba Gabor | last post by:
I have a table with 3 rows, and two pieces of data to display in each row. However, the first element of the last two rows and the 2nd element of the 1st row are very short. This would seem to...
3
by: shubham rastogi | last post by:
hello guys I want to copy or insert records into the previously created table from another table.. For example I have two tables A and B .... I want to copy or insert records from table B into...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.