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.
Author |
Topic |
ZMike
Posting Yak Master
110 Posts |
Posted - 2012-07-15 : 23:16:34
|
IF OBJECT_ID('Customer.dbo.Customers) IS NOT NULLDROP TABLE Customer.dbo.CustomersCREATE TABLE Customer.dbo.Customers( CustomerID INT , Date DATETIME , Active INT , CustomerName VARCHAR (100))DECLARE @StartNumber INTDECLARE @StartMinus1 INTDECLARE @EndNumber INTSET @StartNumber =10SET @StartMinus1 =9SET @EndNumber =1WHILE (@StartMinus1 > 1) BEGININSERT INTO Customer.dbo.CustomersSELECT *FROM CustomersWHERE (Date BETWEEN GETDATE() - @StartNumber AND GETDATE () - @StartMinus1 ) PRINT @StartNumberPRINT @StartMinus1ENDIt did print off everything correctly but I have not figured out why I'm getting the error Msg 8115, Level 16, State 8, Line 56Arithmetic overflow error converting numeric to data type numeric.The statement has been terminated.98Msg 8115, Level 16, State 8, Line 56Arithmetic overflow error converting numeric to data type numeric.The statement has been terminated.87ETC |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-07-15 : 23:35:30
|
is there some insert trigger on Customer.dbo.Customers?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
ZMike
Posting Yak Master
110 Posts |
Posted - 2012-07-16 : 00:33:08
|
visakh16, There should have been. I was so into thinking about the loop I forgot the most basic thing on my insert statement LOL.... Thank youFor anyone interested, the reason I was doing something in this fashion is if I pulled a day at a time (15 + million records) it was pulling way too slow for large chunks, but when I did a day at a time it was very quick.IF OBJECT_ID('Customer.dbo.Customers) IS NOT NULLDROP TABLE Customer.dbo.CustomersCREATE TABLE Customer.dbo.Customers(CustomerID INT, Date DATETIME , Active INT, CustomerName VARCHAR (100))DECLARE @StartNumber INTDECLARE @StartMinus1 INTDECLARE @EndNumber INTSET @StartNumber =10SET @StartMinus1 =9SET @EndNumber =1WHILE (@StartMinus1 > 1) BEGININSERT INTO Customer.dbo.Customers(CustomerID , Date , Active, CustomerName )SELECT CustomerID , Date , Active, CustomerNameFROM CustomersWHERE (Date BETWEEN GETDATE() - @StartNumber AND GETDATE () - @StartMinus1 ) PRINT @StartNumberPRINT @StartMinus1END |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2012-07-16 : 05:59:53
|
I think your WHILE will never end becuase you have not decremented the value of @StartMinus1MadhivananFailing to plan is Planning to fail |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-07-16 : 10:04:42
|
yep...Thats true...Nice catch Madhi ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|