Click here to Skip to main content
15,888,461 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am using Shared Database Schema. It maintains Company data and its branches.
For Example - Company A is main company and its branches are in different states of India. Similarly I have Company B with its branches in other states of India. All data is in shared database.

Issue -
If Company admin of Company A asks me for his company's data (including its branches), how I can provide him?
Is there any tool to filter in database in SQL Server 2008 and extract all data of Company A and export them?

Please help me!

Thank you,
Sneha
Posted

1 solution

Don't know if I understood your question correctly, but sounds like you're talking about WHERE clause of a SELECT statement. See: WHERE (Transact-SQL)[^]

Update based on the comment:

I suggest that you slice this to smaller pieces.

First to get the data from the database, you proper select statement. Based on your description it could be something like:
SQL
select * -- or whatever you want to select
from company c
     branch b
     transation t
where b.companyid = c.companyid
and   t.branchid = c.branchid
and   c.companyid = @companyid

In the previous @companyid is a variable containing proper value.

The next step is the format. If you're required to deliver the results, what's the format to be used? If you're running this query in SSMS by yourself, you can export the data in csv or txt by right clicking on the result grig and selecting Save results. You can also run the results into XML. See: http://msdn.microsoft.com/en-us/library/ms173812.aspx[^] so you can create a small stored procedure which would run the query and possibly format the results.

Third question, how the results should be delivered? If via mail, then you can use for example http://msdn.microsoft.com/en-us/library/ms190307.aspx[^]
 
Share this answer
 
v2
Comments
sgjoshi85 6-Sep-11 1:22am    
Thanks Mika..but i want to export data from different tables (of same database) to the client. Let me explain you -
Following are tables in my database:
1) company table - Master table that contains records of all companies (CompanyID, Company Name)
2) branch table - Master table under company table (BranchID, BranchName, CompanyID)
3) Transaction table - transactions of branches (TransactionID,Description,BranchID). Likewise other tables containing details of branches.

Now, client Company A asked me to export all his company's data. So I want to fetch all data of Company A from all above tables and export it.
Can I directly enter Company ID & fire query and it fetches all data in a package and send to the client (Company A) from backend ?
Wendelius 6-Sep-11 2:03am    
Answer updated
sgjoshi85 6-Sep-11 2:19am    
wow thats great..i got solution.I am using SSMS,can export the data in csv as suggested..
Results should be sent via email. So I got help from the links you given.
Thanks a lott..
Wendelius 6-Sep-11 2:34am    
You're welcome :) If you like, you can mark the answer as accepted.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900