April 13, 2018 at 3:39 am
What am i doing wrong?
Msg 319, Level 15, State 1, Procedure usp_test, Line 20
Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon.
Msg 319, Level 15, State 1, Procedure usp_test, Line 21
Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon.
Msg 319, Level 15, State 1, Procedure usp_test, Line 22
Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon.
April 13, 2018 at 3:51 am
You appear to be using SQL Server 2012. The WITH PARTITIONS syntax is only available in SQL Server 2016 and higher.
John
April 13, 2018 at 3:56 am
Do you perhaps have a link confirming this?
April 13, 2018 at 4:01 am
Just search the documentation for TRUNCATE.
John
April 13, 2018 at 7:09 am
The documentation is pretty clear on this. https://docs.microsoft.com/en-us/sql/t-sql/statements/truncate-table-transact-sql
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
April 16, 2018 at 5:46 am
I'd suggest to drop the partitioning and all the mess associated with it.
Create clustered index started with [BackupDate] on each of the tables.
When retrieving data for a specific backup use such a clause:[WHERE|ON] BackupDate = @BackupDate and BackupID = @BackupID
When deleting the records simply use this:
DECLARE @CutOffDate datetime
DECLARE @BackupDays INT = 7; -- I's expect it to be a parameter of the SP
SET CutOffDate = DATEADD(dd, - BackupDays, GETDATE())
DELETE FROM dbo.StatementData WHERE BackupDate < CutOffDate
DELETE FROM dbo.ProofOfAccountData WHERE BackupDate < CutOffDate
DELETE FROM dbo.PaidupLetterData WHERE BackupDate < CutOffDate
_____________
Code for TallyGenerator
Viewing 6 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply