Transfer database value to excel in a specific cell [closed] - database

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
To start with, I have no idea yet even a code on how to do this. To make things clearer, I want to transfer a database value to excel to a specific location. Lets say I have a saved template (excel) naming RISK.xls. I have 4 tables that has a common column named riskId in which i want to get a specific value to be transferred. Let's put it this way,
Table 1 in database(Department):i want to transfer column department where riskId = 50(sample)
Table 2 in DB(Rate): I want to transfer column inherent where riskId = 50(sample)
table 3 in DB(treatment): i want to transfer column description where riskId = 50
table 4 in DB(strategy): i want to transfer column details where risjId = 50
now i want to transfer selected value in table to be transferred in my excel. Here goes:
Selected Value in Table 1 transferred to excel cell A5.
Selected Value in Table 2 transferred to excel cell B5.
Selected Value in Table 3 transferred to excel cell C5.
Selected Value in Table 4 transferred to excel cell D5.
Plus this option: those tables are related to each other so if in excel table 1 value has multiple table 2 value and each item in multiple table 2 value has its own multiple value which is in table 3 and so on. So one A5 = B5 to B10(sample) and b5 = C5 to c10) like this.
Hope anyone can help me with this.
Thanks and feel free to ask me about my problem.

You could query the database using the "External Data" feature in Excel and create a specific SQL statement that will return the values in a specific worksheet. After that's done, you can reference what's in those cells using formulas.
Check this out to get you started:
http://www.spreadsheetsmadeeasy.com/excel-create-pivot-table-using-sql/

Related

How to capture column changes into new columns in a SQL Server table? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 days ago.
Improve this question
I have a SQL Server table. I need to keep track of 3 columns in that table. Whenever a change happens in one of those columns, the historic information present in that column needs to be moved to a separate column. Every time the change happened, the history column should keep track of all the changes that are being done on that column. May I know how to implement this process?
Example;
ORIGINAL TABLE VIEW:
enter image description here
CHANGE1 TABLE VIEW:
enter image description here
CHANGE2 TABLE VIEW:
enter image description here
CHANGE3 TABLE VIEW:
enter image description here
I read few docs online and they said that I need to enable track changes of SQL database and establish track changes on the table that I need to work with. After that I do not know what to do.
Do I need to write a code that concatenates the data present in the original columns to HIST columns? If so, How can I do it when the changes happen at random point of day? (If I follow this, is there a point to enable change tracking?)

How can I save Pending Changes? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed last month.
Improve this question
I have a SQL table Infos that stores some user information, the user can update his data but needs Administrator validation first,
the primary key of Infos is the referenced a lot in some others tables
Wy question is where chould I store the pending information that need validation ?
Is it a good idea to store them as JSON in a column ?
Treat this as a data modeling question. If the user information requires validation before it can be used in the application, introduce a Infos_UpdateRequest table or somesuch, that the administrator can use, and if approved copy the values from there to Infos.
You could create an Infos_Pending table with the same schema as Infos and the primary key being also a foreign key to Infos. So, your admins could load the pending records:
approval would first update the Infos record with the Infos_Pending values and then delete the Infos_Pending record
rejection would simply remove the Infos_Pending record
I would look at adding a pending approval and is active column to your table.
It would then be easy to identify which of your rows should be displayed. You could even keep older rows around for undo/history purposes.
This would mean you'd need to make changes to the sprocs/code used at your display layer, though.
I would suggest not using json or xml unless it's a situation where you always intend to chnage the entire set of values in contains.

How to overcome save data in table same time by two users [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I am implementing a seat booking application. I have a problem. There is a booking table. If two users try to book a same seat exact same time it will be a problem. How can I overcome this problem. I am using Java 8 and PostgreSQL.
A database system is designed to handle concurrent queries like in your situation by itself.
You however need to make sure, that a seat can only be booked once.
Solution #1 If you insert a new entry in the booking table for each booked seat
INSERT INTO booking (booking_id, seat_id, customer_id)
SELECT ?,?,?
WHERE NOT EXISTS (SELECT seat_id FROM booking WHERE seat_id=?)
This solution will check if there is already a booking entry in the database with the seat_id you are trying to book. This can be also achieved by putting an unique constraint on the seat_id attribute in your table. However in this case your query will fail with an error - since the unique constraint is violated when inserting a duplicated value - while in the solution above the query will execute sucessfully and just not insert any value. This solution is prefered.
Solution #2 If you have one row for every seat in your database and just need to update if its booked
UPDATE booking
SET booking_id=?, booked=true
WHERE seat_id=? AND booked = false
Depending on your JDBC library you are able to replace the ? with your real values.
The database system will handle concurrent queries and only allow one query to pass.

In one to many relationship does there exist element from first table that are not connected to element from second table [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
when we have two tables, suppose A and B,there exists one to many relationship between these two, than can there be element from A that are not connected to any element from B?
One to many relationship between relational tables is a concept that primarily means that if there is a record in table A, then it can have many associated records in table B.
For e.g. customer_id record in table A can have many loans for that customer in table B.
So 1 customer_id associated with many loan_ids in another table.
Coming back to your question, it is possible that 1 loan_id in loan_table can have multiple guarantors in guarantor_table and it is also possible that a loan does not have a guarantor associated with it. So even though there is one to many relationship between the tables it does not mean it will always have many records in table B for one record in table A.
Check this link - What is the difference of partiality and optionality when drawing ER diagrams

Using Relational Algebra, how can I find duplicate rows in a table? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I am completing a piece of homework. I'm not asking for the answer to the question, but just how I'd go about doing it. I need to find duplicates in a single table. For example, if each entry was a user ID and a hobby, how would I find all entries where the user ID and hobby appear exactly the same at least two time? So if I had the following table...
ID | Hobby
----------
1 | Swimming
2 | Running
3 | Football
1 | Swimming
3 | Football
3 | Football
How would I find the User IDs of the users with duplicate entries? (1 and 3)
Perform two identical projections on your table (I'll call them P1 and P2), with the restrictions being the table key (unique identifier) and the attribute that's believed to have multiple occurrences of the same value (attribute). In the context of this post, ID and Hobby would be the projection restrictions.
Retitle the columns for one of the projections. Or in other words, change the names of ID and Hobby, but maybe still something similar. For our example, we'll rename P2's columns to ID2 and Hobby2.
Perform a cross product between P1 & P2. This will allow for each record to pair with every other record. I'll call this table C. click here for a visual
Perform a selection on C with the criteria (specific to this problem) that ID = ID2 and Hobby = Hobby2. This will be table S.
Perform a projection on S to clear out duplicates, which will leave a table that consists of unique records of paired ID and Hobby values. We'll call it P (S).
Apply the difference operator in the fashion of C - P (S). This will take away the cases when a record is compared with its 'counterpart', leaving only records that are true duplicates.
Perform a projection on this resulting table, with the restriction of ID.
This should work for detecting duplicates of any other kind/form. Simply change the criteria to fit the details of the problem at hand, starting at step 4, and on.

Resources