Create a Trigger to output/append mssql results to a file - sql-server

I'm using mssql and I want to create a trigger to append any added data from a table to a file. I'm using express so using the wizard is not an option since it does not save in express edition. The table is small and does not receive data often. The table essentially is used to log notes on a products life test. More or less I want the results in a file for our team and or customers. Thanks in advance for any help on the matter.

Related

SQL Server - Insert data into temporary table from another server

The problem we are fancing is we have to make some inserts/updates into a certain database of one server based on the data from another server. The first idea that came to my mind was using linked servers, but it was rejected by the database management team (unfortunately, we were given no reasons for such a prohibition). I suggested to split the task into two SQL scripts, so we force the first one to print out the data we want to use from the first server, so it could be pasted into de second script por update the second server (it was also rejected).
For short: we have some data in a server A table T, and we want to query T in order to extract some data and insert it into a temporary table of server B without using linked servers. Once the data is inserted into the temporary table then we could write a T-SQL script for use this data to update some tables from server B. Is there any way to accomplish this?
Any ideas would be welcome.
Thanks in advance.
The solution that comes to my mind is, you can make a procedure to save the data in the csv file after each insert. Then, the second server can check the csv file with some conditions like (if it's not empty), insert it into the table in the second server, then run another query to make a csv file empty after inserting it to the second server. Then you can update the second server based on your requirements. I hope this solution helps you.

How to import tables of a database in SQL Server to another SQL Server on a different computer programmatically?

Good day :-), I'm a beginner when it comes to asking questions here so please bear with me..
First, let me state the example problem at hand:
Company "A" has 4 branches, each placed in different provinces. Each branch, including the main company has an application that inputs a person's profile and saves it to SQL Server database. All data entered by the branching companies must be submitted to the main branch once in a month. But the main director doesn't want those data to be submitted via cloud, he wants it in a flash drive and one individual from each of those branches must travel to the main company, and submit the flash drive with the data inside.
Because if I just use backup & restore method, they will overwrite everything.
Thus, I have created a dummy database to hold those data. Same table, and each table column has the same data type as the original.
Using VB.NET how does one export the table of a database to a dummy database programmatically?
And once exported, how does one import it to the main company's database?
I'll be grateful if you provide me solutions or if you can point me out to the right direction. Also is my method correct?
You can import/export data from one server to another by using Linked Server.
we can do this also by using sql scripts for using simple select & insert query referring the "Servername.Database.tableName"
Now, if you need to do this in a timely manner, for example for every night you need to import/export the data, what i would suggest is to use Sql Agent. Here you can provide timing to execute the script such as date time and whether it is recursive etc...
with the script of import /export to targeted to specific server.
Ps:
Other approch would be to you use SSIS.
Hope this helps.
Thanks,
Satish

Easiest way to store Excel invoice data into SQL Server database?

I want to link an invoice template in Excel to a SQL Server database.
The invoice currently contains only a few very basic fields like user/customer/date/item-id/description/quantity/Total etc.
In future more fields will be required.
What's the easiest way to store all that invoice data in realtime to a SQL Server database when the user presses enter in the invoice?
How many tables will I need to create in SQL Server?
The end users are not tech savvy at all, I need to deploy this solution without any technical requirements from them.
Thank you.
The best way to do this is to create an SSIS package that sucks up the excel spreadsheet and captures the data say once a day. The excel file will need to be in the same location, say a network folder and the structure will also have to be the same, meaning the columns and their names once setup will have to also be the same. Otherwise, it's best to have something like a web front end or a fat32 client (basically build an app in Visual Studio or something) that allows data input directory to the SQL server.
Check out this link to learn about it:
http://knowlton-group.com/using-ssis-to-export-data-to-excel/

What would be the best method for building Dynamic Reports from my SQL DB Data?

I am building a simple database with about 6-7 tables. I will be setting a schedule to do a clean import from a .txt file.
I want to take this data and create a report, like I would do in an excel spreadsheet, convert it to a pdf and post it to our company intranet for those interested to access it.
I'm trying to think of the best way to build my report. Would I just use an excel spreadsheet with a direct connection to the database? Would I create some sort of console application (c/c#/vb/vb.net) that would query the db, generate the report in an excel file, convert to pdf and save?
I'm quite comfortable in these different languages, just not as experienced in the reporting services (although I do have a lot of experience working with EXCEL and VBA Macros) but I want to get into it (SSRS) and get familiar with it as I will be doing a lot of projects like this in the future. This is seems like an easy one to get my hands dirty with and learn and build off of.
Any insight or suggestions would be greatly appreciated.
Thanks so much!
My suggestion:
Create desired SQL queries to retrieve the data in desired form
Link these queries to your Excel sheet, perhaps directly in form of pivot tables for aggregation of results
Using VBA, you can easily create PDF from the data at the click of a button
The initial design will be time intensive, but after that, everything is automated and one just needs to press the button that creates the PDF.
How to link Access queries to your Excel file:
Data --> Get external Data
You can easily refresh all data whenever you open the Excelsheet by using the code below in the On Open event of the workbook:
ThisWorkbook.RefreshAll
If you need further clarification, do not hesitate to ask
If your end goal is to create a PDF that will be out on your intranet then I would create the report in SSRS. Then you can schedule it to run and output a PDF to your network location.
I've had good experiences using a pivot table in Excel which is a connected table to your SQL database.
In the connection parameters in Excel there is a field where you can define your SQL query, whether it be to call a stored procedure or just a simple SELECT statement.
The main reason I prefer a pivot table SQL connection rather than a normal table connection is because if you have a chart that references the connected table, the chart formatting will be reset when you refresh your connection (if you need to updated your report).
If I use a chart that references a pivot table (or a pivot chart) then the formatting is retained.

Select existing data from database to create test data

I have a SqlServer database that I've manually filled with some test data. Now I'd like to extract this test data as insert statements and check it in to source control. The idea is that other team members should be able to create the same database, run the created insert scripts and have the same data to test and develop on.
Is there a good tool out there to do this? I'm not looking for a tool to generate data as discussed here.
If you want a light-weight solution, I would recommend sp_generate_inserts. It is a store procedure you can create on your DB and pass in a variety of arguments to generate insert statements of all the data in the target table.
EMS DB Extract for SQL Server (http://www.sqlmanager.net/en/products/mssql/extract) seems to do what you want, and it seems to be free.
Hope this helps,
Robin
Red-Gate SQL Data Compare will do this. Just create a blank data base with the same schema, and run a compare against the original and the blank database. It will generate scripts to insert all of your test data.
This works http://www.sqlscripter.com/
New version of SQL Scripter (V2.1) was released last month.

Resources