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

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Splitting a table based on it's content

Author  Topic 

mwginge67
Starting Member

2 Posts

Posted - 2012-12-24 : 05:55:04
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)

17689 Posts

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


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2012-12-24 : 07:42:42
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

5 Posts

Posted - 2012-12-24 : 07:50:03
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

2 Posts

Posted - 2012-12-28 : 04:50:34
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
Aged Yak Warrior

550 Posts

Posted - 2012-12-28 : 18:20:47
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
   

- Advertisement -