SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Splitting a table based on it's content
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

mwginge67
Starting Member

United Kingdom
2 Posts

Posted - 12/24/2012 :  05:55:04  Show Profile  Reply with Quote
I have a table with 1000 records and each record is asssociated with a customer. This table will change each month.

I want to create individual views of that table based on those customers in it. So, for example if there are a total of 20 customers I will get 20 views.

I want to automate this process.

Any ideas?

khtan
In (Som, Ni, Yak)

Singapore
17593 Posts

Posted - 12/24/2012 :  06:02:44  Show Profile  Reply with Quote
that doesn't sounds like a very good idea. Can you elaborate why do you want to do this ?


KH
Time is always against us

Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22754 Posts

Posted - 12/24/2012 :  07:42:42  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
Why don't you have a stored procedure that select each customer's data based on parameter for customerid? Creating a view for each customer is nothing but calling trouble in future

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Sandips
Starting Member

India
5 Posts

Posted - 12/24/2012 :  07:50:03  Show Profile  Reply with Quote
if you do not want to use stored procedure you can use table valued function also.
so you can use the Function in place of view
Ex : Select * from dbo.FN_GetDataByCustID(@CustID)



“Normalize ’till it hurts, then denormalize
’till it works.”
Go to Top of Page

mwginge67
Starting Member

United Kingdom
2 Posts

Posted - 12/28/2012 :  04:50:34  Show Profile  Reply with Quote
Thanks for the replies. In answer to "why I need to do this?" My finance people need to invoice each customer and attach the detail to each of the invoices.

I'm not new to SQL but still finding my way. I think a stored procedure or table valued function will work equally well I'm just not sure about the code syntax.

Can anyone recommend a good SQL book? I have SQL Server 2008 for Dummies but it's not helping me much. I need something that's less about the design and management of databases and more about manipulating data, complex querying and reporting.

Thanks again

Go to Top of Page

ScottPletcher
Constraint Violating Yak Guru

USA
362 Posts

Posted - 12/28/2012 :  18:20:47  Show Profile  Reply with Quote
I don't mind the views so much, but why do you want separate tables?

You can just key the table by date first, then the other columns.

Maintaining all those tables will be the real headache.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000