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 2005 Forums
 Transact-SQL (2005)
 add every column from last existing one to...

Author  Topic 

FriendOfGhost
Starting Member

9 Posts

Posted - 2010-10-09 : 18:24:47
Okay, here's a new question:
Table1 have these columns
Field1-Field2-Field3-Field4-Field5

I'll call my sp with a parameter of, lets say 10 (integer)

sp have to check last field (which is field5)
and add columns from 5 to parameter which is 10
Field6-Field7-Field8-Field9-Field10

result columns should be:
Field1-Field2-Field3-Field4-Field5-Field6-Field7-Field8-Field9-Field10

any help please ?

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-10-09 : 18:26:15
Why aren't your columns better named? Is it not going to be properly normalized?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

FriendOfGhost
Starting Member

9 Posts

Posted - 2010-10-09 : 18:34:30
Column names are actually week numbers of year. they go like Week5226, Week5227... until today. I need weekly sales in my project. I can calsulate them with sps and views but its too slow. every report takes 5 to 10 minutes for only one year as there are 800 products and 200 different companies. do the math. my solution was building a table with weekl columns and update these values with triggers in sales table.

question is, user can make a sales today and trigger will update the value for this week. 2 month later, when he make another sales there will be a 2week number gap'. my quesiton is about "filling this gap"

by the way, if you have any better (fast) idea to get weekly sales I would be happy to hear it.
thanks.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-10-09 : 18:53:54
You've got a design problem. You should not have columns like this. Your table is not properly normalized.

We'll need to see some sample data in order to help you with the gaps plus the design and speed. But you need to a big table redesign to fix your issue.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

FriendOfGhost
Starting Member

9 Posts

Posted - 2010-10-10 : 06:22:59
I solved the problem. thanks.
Go to Top of Page
   

- Advertisement -