Add 1 or more email with append structure - abap

We have a table that is filled by a program with a web service. This table has customer data like custno, name tele1, tele2, addr etc. They want to add emails but they do not know how many fields each customer has. They told me that we can handle this by adding an Append Structure to the table. I look in the internet but I can't find a way to do this with Append Structure.
What they want is to have 1 record for Elias with all his data and under this to put his 3 email.
Can we do it with Append Structure and how.
Thanks in advance
PS. This is an important correction. This is not a DB table but it is a structure. This Structure ws_customer is used as IMPORT in order to pass the customer data for creating or updating the sap customer. So they asked from me to add an APPEND STRUCTURE and add dynamically as much emails as the customer has. For example the customer ELIAS with CUSTNO 145 ADDRESS BROWN 6 has emails asimof#gmail.com, asimof#hol.gr and asimof#greece.gr. The Append Structure will have 1 field and for the record of this customer we will have 3 emails.
Is it possible to do this?

why don't you add a table of email adresses to this structure? in my oppinion, you could do it just the way JozsefSzikszai described it.
When you have your structure, you can append a table to this structure and then you can always add as much email adresses to this table as you want
a example could look like this:
TYPES BEGIN OF your_structure,
field1 TYPE string,
field2 TYPE string,
email TYPE STANDARD TABLE OF string,
END OF your_structure.
when you then have your variable of the type your_structure, you can add email adresses like this:
DATA your_variable TYPE your_structure.
INSERT 'email#adress.com' INTO TABLE your_variable-email.
When your_structure is a DDIC structure and not defined by code, you could append the table to the DDIC structure and use it just the same way

Related

Modifying a SQL table to insert data from an existing row into the previous row

I have a SQL table called RawData with the following six columns (all type VARCHAR):
Name StreetAddress State Phone Website Email
I import new data from a CSV file into this table on a regular basis and 99% of it is formatted correctly. For 1% of the data, for reasons that I understand but are not important for this question, the data is imported such that all of the first five columns (Name, StreetAddress, State, Phone, Website) have data that is formatted correctly but the sixth column Email is blank. Furthermore, the email is imported into its own row immediately below this "problem" row but the email is placed in the Name column. These situations are readily identified begins the email address is always inserted in the Name column with the mailto: prefix .
What I would like to do is devise a query to take the incorrectly placed email address from the Name, strip the mailto: prefix and then place it into the Email column in the previous row. I would then like to delete the row with the 'mailto:' email in the `Name' column.
I've done a bit of research and believe that I need to use a cursor to copy the data from the row below the correct row and insert it into the Email column but having never used cursors before, I am struggling to come up with anything. Any help would be appreciated.
Edit: For the purposes of brevity, I omitted that the table does contain an identity column ID.
In SQL Server, there is no concept of "previous" row. You are going to need to add an identity column to the table so you can identify these situations. Fortunately, you can insert your data into a view, so the identity is automatically incremented in the load order.
Once you have the id, you can use an update:
update nd
set nd.email = stuff(ndnext.name, 1, 7, '')
from newdata nd join
newdata ndnext
on nd.id = ndnext.id - 1
where ndnext.name like 'mailto:%';
Once you have verified that this is correct, you probably want to do:
delete nd from nd
where nd.name like 'mailto:%';

How to create a table from the attributes of another table that contain a key word?

I have a SQL table called SCUBA_CLASSES with attributes ID and NAME. In the table are different kinds of scuba diving classes from beginner to advanced levels. There is a second table called REQUIRED_BOOKS that has the attributes ID and TITLE that contain all the books required by different scuba classes.
I'd like to create a new table called INTRO_REQUIREMENTS with an attribute ID. It will contain a list of all the books required by scuba classes whose name starts with the word "Introduction". How would you create this?
So far I have:
CREATE TABLE INTRO_REQUIREMENTS AS
SELECT SCUBA_CLASSES.ID
FROM SCUBA_CLASSES, REQUIRED_BOOKS
WHERE SCUBA_CLASSES.ID = REQUIRED_BOOKS.ID;
I can generate a list of classes with required books but can't figure out how to add the requirement that the name of the class has to start with "Introduction".
add one more condition in where clause using using AND and Search name using LIKE.
CREATE TABLE INTRO_REQUIREMENTS AS
SELECT SCUBA_CLASSES.ID
FROM SCUBA_CLASSES, REQUIRED_BOOKS
WHERE SCUBA_CLASSES.ID = REQUIRED_BOOKS.ID
AND name LIKE "introduction%";

SQL Server: copy, replace and paste within same table

I am pretty new to SQL and hope someone can help me with the following general question.
I have a large table with several columns where I want to do 3 things via one stored procedure:
Select all data for country Great Britain (GB), e.g. by using something like the following:
SELECT *
FROM XYZ_TableData
WHERE (countryCode LIKE 'GB')
Copy all the above to a temp table and replace 'GB' in column countryCode by 'XX'.
Copy the data from the temp table and insert it into the above table (i.e. with the copied data showing XX instead of GB).
Can anyone help me to get a start here?
Do it all in one step, no temp table required:
insert into mytable(field1,field2,field3,country)
select field1,field2,field3,'XX' As Country from mytable where country='GB'
This assumes you are trying to append a new set of records to the table, not update the pre-existing records. I read the question one way, but Theresa read it another...guess you need to decide what you meant.
Why aren't you doing an UPDATE?
UPDATE XYZ_TableData
SET countryCode = 'XX'
WHERE countryCode = 'GB'

Avoid sql_variant but use what?

My database holds template forms and real forms having values. Users will be able to create custom template forms with different types of fields. I will keep values in a separate table.
Forms table:
Id | Name | TemplateId
FormFields table:
Id | FormId | Name | ValueType (nvchar)
Values Table
FieldId | Value
When user designs a form it is saved into forms table having TemplateId NULL. Also FormFields table stores the fields that will be used for this form.
Later when user creates a real form using that template, the real values of this form (derieved from FormFields) will be stored in Values table.
Now, the value column in Values table seems to be sql_variant type. If I don't use sql_variant how can I solve this problem?
Ps: What about creating different tables for each kind of values? TableIntValues, TableBoolValues etc?
http://www.jotform.com/ can be a good sample for my project.
I would suggest using separate columns for the separate data types, along these lines:
FieldId | StringValue | IntegerValue | DateTimeValue
That way you can have queries run over the data sensibly, and also keep it type safe. You would obviously need logic to ensure that the data gets populated correctly, and a constraint to ensure only one column is populated and not all are NULL.

Update TAG Relational table from select match on main table with keywords field and tag table with individual keywords

I imported the Software PAD File Database from http://paddatabase.net/download.html into Microsoft Access in a table called main:
MAIN
-----
ID
ProgramName
Keywords
.
.
I created two new tables: Tags and TagSoftwareRel.
Tags
--------
ID
Tag
TagSoftwareRel
--------------
ID
SoftwareID <- (MainTable)
TagID <- tags table
I extracted all the keywords from the field Keywords as individual words in the Tags table. They Keywords field from Main looks like this:
Keywords
Paul, animated, moving monk, paulaner
Image,Imaging,Graphics,Rotate,Resize,Effects,
Sharpen,Blur,JPEG,TIFF,BMP,WBMP,PSD,GIF,PDF,Format,ICM,ICC,CMYK,
thumbnail,Convert,Display,AJAX,AVI,red-eye removal,lossless JPEG transform
correction, rich,internet,applications,ebooks,webmaster,authoring,
What I want to do is create a SQL Query which Inserts the tagID from the tags table into tagsoftwarerel.tagid and the related softwareID from the main table into tagsoftwarerel.softwareid by using a where tags.tag like main.keywords
I'm sort of at loss of where to start with this.
As it is a public DB I can provide a copy of the database to anyone interested.
Any assistance would be most appreciated. Thank you.
I assume that the field ID from the TagSoftwareRel is an autovalue or identity. That means the value is created automaticly by inserting a new row:
I understand that you already filled the Tags-Table.
Here is a query which would fill the TagSoftarerel-Table:
Insert into TagSoftarerel (SoftwareID, TagID)
Select m.Id,
(Select T.TagId from Tag T where T.Tag = m.Keyword) as TagId
from MAIN m
Advice:
I think you could find a better solution. The Tag-information is redundant in your solution.
If you would just add the Tag.Id to the main-table you could get rid of the Keyword column and store the tag-information solely in the tag table, where it belongs to.