Row 1 with identity 1 has rolled over to new quarter row 4 with identity 4 ( qtr fields are changed ) Row 2 with identity 2 has rolled over to new quarter row 5 with identity 5. Same with last row as well.
Here, i have another table called "ident_map" with columns like (old identity, new identity ) and during rollover i am supposed to load ident_map table with old and new identity. So after rollover is complete, ident_map table should look like
1,4 2,5 3,6
I know using output clause I can capture the new identity values. 4,5,6 in this case. But is there any way to capture both old identity and new identity during rollover so that i can load the ident_map table with old and new identity.
i am trying to find a way to link an 'initial' Sale ID of a product to 'future' Sale IDs of products that will trace back to the original Sale ID.For example, if I call the original sale , 'Sale ID #123', how can i link future Sale ID's (child[ren]) and all future sales to the original Sale ID #123? Can I use a Surrogate Key or similar function?
Parent:Sale ID #123 Children: Sale ID # 456, Sale ID #789, Sale ID #.....
how I can link the original Sales ID (Parent) to Sale ID's (child[ren]) of future purchases currently existing and in the future going forward?
I want to calculate the sum of actual sales until a date and forecast sales after a date.I am not sure what the best approach to this problem is, but I have tried my best with the following approach. Any better ways to solve this (using DAX).
I have created a parameter table that offers the last date of each month as possible choices to the user. I have tried to create a measure that sums actual sales up until this date.
Does anyone know of a way to use a funtion for returning records based on fiscal reporting periods like Quickbooks uses for example "This Month", "Last Month", "This Quarter", "Last Quarter", "This Year", "Last Year". While I realize that I can create a very long date time parsing routine for this but it is not very elegant or useful. I thought there might be a way to do this already with an existing function.I have created a stored procedure that I pass a @ViewRange Parameter to and it returns the records that I want but I need this ability in several procedures and wanted to turn it into a stored procedure.IF @ViewRange = 'This Month' SELECT TOP 20 Customer.LastName AS Customer, SUM(Sales.AmtCharge) AS Amount FROM Customer INNER JOIN Sales ON Customer.CustNo = Sales.CustNo WHERE (MONTH(Sales.InvDate) = MONTH(CURRENT_TIMESTAMP)) AND (YEAR(Sales.InvDate) = YEAR(CURRENT_TIMESTAMP)) GROUP BY Customer.LastName ORDER BY SUM(Sales.AmtCharge) DESC;IF @ViewRange = 'Last Month' SELECT TOP 20 Customer.LastName AS Customer, Sum(Sales.AmtCharge) AS Amount FROM Customer INNER JOIN Sales ON Customer.CustNo = Sales.CustNo WHERE(MONTH(Sales.InvDate) = MONTH(CURRENT_TIMESTAMP) - 1) And (YEAR(Sales.InvDate) = YEAR(CURRENT_TIMESTAMP)) GROUP BY Customer.LastName ORDER BY Sum(Sales.AmtCharge) DESC; Any ideas?
I actually ran this on a reporting copy of my DB (restored once a week). I would guess the errors are present in the main copy as well. I fear running the check during production hours as it takes 2.5 hours and the system (4 processor) is under a lot of load for almost the entire day and much of the night.
It looks like the repair with data loss is my only choice but I would definitely prefer to know which rows are messed up. I'm also wary of running the repair as it's probably going to take well over an hour on the huge sessions table. I don't know how it got in this corrupted state. I inherited a DB of this size (50GB) that's been known to be very sensitive to any admin or index fiddling due to the high load. After I get this repaired I feel I should run the CHECKDB in a maintenance plan but I'm not sure if this will cause slowdowns in itself if it runs for 2.5 hours. The DB backup takes over 2 hours leaving almost no spare time in the off peak time.
Any advice/suggestions? Thanks.
DBCC results for 'dbloc'.
DBCC results for 'sessions'. Server: Msg 8928, Level 16, State 1, Line 1 Object ID 462624691, index ID 0: Page (1:9517861) could not be processed. See other errors for details. Server: Msg 8928, Level 16, State 1, Line 1 Object ID 462624691, index ID 0: Page (1:9659261) could not be processed. See other errors for details. Server: Msg 8928, Level 16, State 1, Line 1 Object ID 462624691, index ID 7: Page (1:5825743) could not be processed. See other errors for details. Server: Msg 8928, Level 16, State 1, Line 1 Object ID 462624691, index ID 7: Page (1:5890660) could not be processed. See other errors for details. Server: Msg 8928, Level 16, State 1, Line 1 Object ID 462624691, index ID 7: Page (1:5931145) could not be processed. See other errors for details. Server: Msg 8928, Level 16, State 1, Line 1 Object ID 462624691, index ID 7: Page (1:5950021) could not be processed. See other errors for details. Server: Msg 8928, Level 16, State 1, Line 1 Object ID 462624691, index ID 7: Page (1:5978420) could not be processed. See other errors for details. Server: Msg 8928, Level 16, State 1, Line 1 Object ID 462624691, index ID 7: Page (1:5988261) could not be processed. See other errors for details. Server: Msg 8928, Level 16, State 1, Line 1 Object ID 462624691, index ID 7: Page (1:6046306) could not be processed. See other errors for details. Server: Msg 2511, Level 16, State 1, Line 1 Table error: Object ID 510624862, Index ID 0. Keys out of order on page (1:11853027), slots 109 and 110. Server: Msg 2511, Level 16, State 1, Line 1 Table error: Object ID 510624862, Index ID 0. Keys out of order on page (1:11853027), slots 112 and 113. Server: Msg 2511, Level 16, State 1, Line 1 Table error: Object ID 510624862, Index ID 0. Keys out of order on page (1:11853027), slots 113 and 114. Server: Msg 2511, Level 16, State 1, Line 1 Table error: Object ID 510624862, Index ID 0. Keys out of order on page (1:11853027), slots 114 and 115. Server: Msg 2511, Level 16, State 1, Line 1 Table error: Object ID 510624862, Index ID 0. Keys out of order on page (1:11853027), slots 117 and 118. Server: Msg 2511, Level 16, State 1, Line 1 Table error: Object ID 510624862, Index ID 0. Keys out of order on page (1:11853027), slots 118 and 119. Server: Msg 2511, Level 16, State 1, Line 1 Table error: Object ID 510624862, Index ID 0. Keys out of order on page (1:11853027), slots 121 and 122. Server: Msg 2511, Level 16, State 1, Line 1 Table error: Object ID 510624862, Index ID 0. Keys out of order on page (1:11853027), slots 122 and 123. Server: Msg 2511, Level 16, State 1, Line 1 Table error: Object ID 510624862, Index ID 0. Keys out of order on page (1:11853027), slots 124 and 125. Server: Msg 8928, Level 16, State 1, Line 1 Object ID 510624862, index ID 0: Page (1:11858027) could not be processed. See other errors for details. Server: Msg 8939, Level 16, State 1, Line 1 Table error: Object ID 510624862, index ID 0, page (1:11858027). Test (IS_ON (BUF_IOERR, bp->bstat) &&bp->berrcode) failed. Values are 2057 and -1. Server: Msg 8928, Level 16, State 1, Line 1 Object ID 510624862, index ID 0: Page (1:11865547) could not be processed. See other errors for details. Server: Msg 8939, Level 16, State 1, Line 1 Table error: Object ID 510624862, index ID 0, page (1:11865547). Test (IS_ON (BUF_IOERR, bp->bstat) &&bp->berrcode) failed. Values are 2057 and -1. Server: Msg 8928, Level 16, State 1, Line 1 Object ID 510624862, index ID 2: Page (1:11889147) could not be processed. See other errors for details. DBCC results for 'sessions'. There are 153364096 rows in 3102681 pages for object 'sessions'. CHECKDB found 0 allocation errors and 9 consistency errors in table 'sessions' (object ID 462624691). DBCC results for 'map'. Server: Msg 8939, Level 16, State 98, Line 1 Table error: Object ID 510624862, index ID 2, page (1:11889147). Test (IS_ON (BUF_IOERR, bp->bstat) &&bp->berrcode) failed. Values are 2057 and -1. Server: Msg 2511, Level 16, State 1, Line 1 Table error: Object ID 510624862, Index ID 3. Keys out of order on page (1:11931268), slots 206 and 207. Server: Msg 2511, Level 16, State 1, Line 1 Table error: Object ID 510624862, Index ID 3. Keys out of order on page (1:11931268), slots 209 and 210. Server: Msg 2511, Level 16, State 1, Line 1 Table error: Object ID 510624862, Index ID 3. Keys out of order on page (1:11931268), slots 210 and 211. Server: Msg 2511, Level 16, State 1, Line 1 Table error: Object ID 510624862, Index ID 3. Keys out of order on page (1:11931268), slots 230 and 231. Server: Msg 8928, Level 16, State 1, Line 1 Object ID 510624862, index ID 11: Page (1:11988308) could not be processed. See other errors for details. Server: Msg 8944, Level 16, State 1, Line 1 Table error: Object ID 510624862, index ID 11, page (1:11988308), row 194. Test (ColumnOffsets <= (nextRec - pRec)) failed. Values are 7251 and 18. Server: Msg 8928, Level 16, State 1, Line 1 Object ID 510624862, index ID 11: Page (1:12003992) could not be processed. See other errors for details. Server: Msg 8939, Level 16, State 1, Line 1 Table error: Object ID 510624862, index ID 11, page (1:12003992). Test (IS_ON (BUF_IOERR, bp->bstat) &&bp->berrcode) failed. Values are 2057 and -1. There are 15576829 rows in 65455 pages for object 'map'. CHECKDB found 0 allocation errors and 23 consistency errors in table 'map' (object ID 510624862). Server: Msg 8928, Level 16, State 1, Line 1 Object ID 1790629422, index ID 16: Page (1:11471717) could not be processed. See other errors for details. Server: Msg 8944, Level 16, State 1, Line 1 Table error: Object ID 1790629422, index ID 16, page (1:11471717), row 88. Test (ColumnOffsets <= (nextRec - pRec)) failed. Values are 3500 and 28. Server: Msg 8928, Level 16, State 1, Line 1 Object ID 1790629422, index ID 16: Page (1:11474112) could not be processed. See other errors for details. Server: Msg 8944, Level 16, State 1, Line 1 Table error: Object ID 1790629422, index ID 16, page (1:11474112), row 108. Test (ColumnOffsets <= (nextRec - pRec)) failed. Values are 745 and 20. DBCC results for 'links'. There are 9919777 rows in 124284 pages for object 'links'. CHECKDB found 0 allocation errors and 4 consistency errors in table 'links' (object ID 1790629422). CHECKDB found 0 allocation errors and 36 consistency errors in database 'dbloc'. repair_allow_data_loss is the minimum repair level for the errors found by DBCC CHECKDB (dbloc ). DBCC execution completed. If DBCC printed error messages, contact your system administrator.
After upgrading a server from SQL Server 2000 to 2005, an index was suddenly being reported as corrupt in the SQL Server log (probably every time an Insert was done). DBCC CHECKDB / CHECKTABLE reported no errors, with or without the new WITH DATA_PURITY option.
Anyone else experienced something similar?
How can an index be reported as corrupt when DBCC doesn't report it?
Dropping and re-creating the index solved the problem. I've restored a backup of the database (made before dropping/re-creating the index) to try repeating the problem, but no success so far.
I have a table that contains 1.6 million rows, and is about 2.6GB in size.One of the columns is ntext and contained some xml.Realistically, I don't need the xml for anything older than about 2 months, however, i'd like to keep some of the data in the other fields.I decided that if I updated the xml to blank, I would see some considerable space savings, however that doesn't appear to be the case.This is the output of sp_spaceused for my table
name rows reserved data index unused CommitmentsForPosting1660979 2740336 KB 1857104 KB312 KB882920 KB
After I updated the table to remove the xml, the output of sp_spaceused remained the same.My first thought was that it was probably statistics, so I updated statistics for the table, and nothing changed.I then updated statistics for everything in the database, still no change.I then ran DBCC CLEANTABLE for that table. I didn't really expect it to make a difference, and no surprise, it didn't.
The index on the table is a clustered index on just a GUID column.I rebuilt the index and again it still made no difference (that's a bit of a lie - index_size changed by a few hundred KB)my next test was to run 'select * into XXX from YYY' to create a copy of this table with the same data and data types. I also created the same clustered index from the original table onto the new one.If I then run sp_spaceused on this new copy of the table, I see what I expect to see in sp_spaceused - a table using approximately 256MB of space
name rows reserved data index unused SPS_TEST 1660979 266400 KB 266400 KB 304 KB56 KB
To be honest, this isn't hugely critical, but I'm just curious as to why the original table is still reporting 2.6GB size, when I think it should probably be nearer 256MB.
Hi, I have SQL Server 2005 Developer Edition installed on my laptop. At this time, our servers here are currently running SQL Server 2000 Enterprise edition. When I try to use the DTS import/export wizard to transfer records between two SQL Server 2000 databases, SQL 2005 always reports the transfer as successful! Although when you check the destination table there is only ever 1 record transfered
This has happened every I have attempted, on any tables, are there any fixes to either perfmit the copy of all records or at least report the error condition that prevents records being transfered?
Using BULK Insert with a format file I am receiving the following message:
Server: Msg 7399, Level 16, State 1, Line 1 OLE DB provider 'STREAMS' reported an error. The provider did not give any information about the error. The statement has been terminated.
I am running SQL Server 7.0 w/ SP1 applied. The same data file and format files work fine if I use bcp.
I have a report that is sent via email to a list of recipients. When I look at the subscription in 'My Subscriptions' the value in the Status column states that the message was 'sent successfully', however the email does not appear in the inboxes of any of the intended recipents. The report renders OK via the browser and only takes a few seconds to process. The subscription exports the report as an Excel file. The excel file is approx 8MB in size but this is still below the attachment size limit for internal emails within my organisation. The subscription is tied to a shared schedule. Other reports that are tied to the shared schedule are shown as successful in 'My Subscriptions' and also appear in the inboxes of recipients. All email address are correct.
I forgot to mention, the report was successfully received by all recipients until very recently and the report has not been modified since this time.
I receive an error message in event log when i try to connect to the Database Server using ODBC on a client machine. The database server is running on Windows 2003 Server Standard Edition and the client machine is Windows XP Professional. Following is the error message from the event log:
2147467259 - [Microsoft][ODBC SQL Server Driver][SQL Server]Login failed for user 'sa' because the account is currently locked out. The system administrator can unlock it.
What causes the error to occur and how to resolve it?Appreciate for your assistence.
Msg 7399, Level 16, State 1, Line 1 The OLE DB provider "VFPOLEDB" for linked server "tele" reported an error. Access denied. Msg 7301, Level 16, State 2, Line 1 Cannot obtain the required interface ("IID_IDBCreateCommand") from OLE DB provider "VFPOLEDB" for linked server "tele".
OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "tele2" returned message "The Microsoft Jet database engine could not find the object 'prospect_divu'. Make sure the object exists and that you spell its name and the path name correctly.". Msg 7311, Level 16, State 2, Line 1 Cannot obtain the schema rowset "DBSCHEMA_COLUMNS" for OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "tele2". The provider supports the interface, but returns a failure code when it is used.
I have a report which totals sales by customer. Then table footer has a grand total of all customer sales. I would like to get a percent of each customer's sales against the total sales. How do I get the sum from the table footer to use in an individual customer row?
I have inherited a server on which is a maintenance plan with two subplans on different schedules. In each subplan there are Execute T-SQL tasks with scripts for index rebuilds. Each task is set up with a Completion arrow to the next task and a Failure arrow to a Notify Operator Task. I was asked to add a task for index rebuilds to a specific subplan for a specific database, which is what the other tasks also do. I discovered that my task was failing but the others were fine. No notification was sent about my task failing even though the job is marked in MSDB as a failed job. I have sent a test email using the "Send Test Email..." option when right clicking Database Mail in SSMSand I receive an email so I know Database Mail works.
I set up a test job to model the index job that I can't get notifications from. I have two T-SQL tasks that just select the top row from a small table. The first task has a syntax error that I did so it would fail. I have a failure arrow to a Notify Operator Task and a Completion arrow to another T-SQL task with no syntax error which has a Success arrow to a Notify Operator task. As expected, when I execute this job I receive one failure email and one success email.
The only other troubleshooting step I know to try is to add a Notify Operator task before my failing task. That Notify Operator task will hopefully fire to tell me that the previous step was successful. I am not having problems with the other steps so I was just thinking I would try to get the subplan to send me a success email about one of the steps that has been working fine.
There is a table named INCOME that has INCOME column for each day and DATE column starting from Aug. 29 1980. How to calculate income summary by each quarter? Thanks.
I am uisng VS 2005 to build reports for SQL 2005. The problem is with getting the Quarter() function, mentioned in the BOL, to work in the report builder. When I build an expression and try to use the function as noted in the BOL I receive an error stating that the name "Quarter" is not declaired. When I use the expression builder to build the expression the function is not available in the builder, which is probably why I get the error.
I am assuming there is some sort of service pack of hot fix I need to apply to my VS but have not been able to locate which one. I have verified that I have all of the recent service packs applied for VS and SQL server 2005 but I am still unable to see/use this function.
Any help would be greatly appreciated. I need this function for my financial reports.
I am using QUARTER(startdate) formula to retrieve the quarter of a specific datetime and to store in my calculated field in dataset. But while running its showing "error: [BC30451] Name 'QUARTER' is not declared".
There is a way to get the non empty max calendar quarter of the year and the last year. For example, the max calendar quarter of the last year should be 4, and in this moment the max quarter of this year should be 3.
I am building a report in SSRS and trying to avoid query the DWH database. I want to run every query against the cube.
here DATEADD(mm, -11, DATEADD(mm, DATEDIFF(mm, 0, GETDATE()), 0)) makes Apr of last year included because that is the first month in 2nd Quarter of last year. But in next month we're in Apr and I need make -11 as -12 in above code to include Apr of last year. And same reason if we're in Feb. 2014 then I need change -11 to -10.
So how can I calculate this to make the number fit into the code or some other way to get the same effect? I need get all last 4 quarters based on current month (include current Quarter).
I am trying to group counts by week,month,quarter, year for a particular activity type and I'm having issues.Here's my code so far:
SELECT distinct EmailAddressID, emailaddress, SUM(CASE WHEN [ActivityDate] >= DATEADD(WEEK, DATEDIFF(WEEK, 0, @DT), 0) THEN SUM(CASE WHEN EmailActivityType = 'OPEN' THEN 1 ELSE 0 END) END AS WeekTotalOpens FROM EmailActivity WHERE DATEPART(YEAR, [ActivityDate]) = DATEPART(YEAR, @DT) GROUP BY EmailAddressID,emailaddress Desired Output: EmailAddressId EmailAddress WeekTotalOpens MonthTotalOpens etc. then WeekTotalClicks and so on....
SQL doesn't seem to like the sub-aggregate. What is the best way to approach?
Hello,I have a query that I would like to schedule in DTS. The criteria ofthis query checks for records in the table that are within the currentquarter. Here is what I have.WHERE submit_date BETWEEN '01/01/2005' AND '03/31/2005'I would like to dynamically generate the Quarter End and QuarterBeginning dates within my where clause based on the date that DTWSpackage is being executed on. Can anyone show me how this can beaccomplished?Thank You.
I have a program that calls queries (OLAP system) the system includes a dimension of date: Year, Quater, Month, Week
When the result appears in the table, it is not in order? Only the year is in oredr and after that each heirachy is wrong and not in order....not sure how to do this!!!
any help would be grateful!!! not sure what I should be looking at.....
How do I get first day of last month of previous quarter from today's date? I know my question is little confusing. I need to get 06/01/2014 using t-sql.