Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

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

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?

In (Som, Ni, Yak)

17689 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 ?

Time is always against us

Go to Top of Page

Premature Yak Congratulator

22864 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


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

Starting Member

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

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

Aged Yak Warrior

550 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  
 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.02 seconds. Powered By: Snitz Forums 2000