A new security rule is now in place where TRUNCATE TABLE must be replaced with DELETE TOP & a Loop. TRUNCATE TABLE appears to have some security risks per the DBA Team? Of course, we need to replace the 1 line statement with logic we develop for DELETE TOP & Loop.
I am getting an error message "Msg 214, Level 16, State 2, Procedure sp_executesql, Line 1
Procedure expects parameter '@statement' of type 'ntext/nchar/nvarchar'.".
What am I missing here? Pseudo Code below...
Thanks in Advance!!!
Steve Medvid
IT Consultant & Web Master
I am getting an error message "Msg 214, Level 16, State 2, Procedure sp_executesql, Line 1
Procedure expects parameter '@statement' of type 'ntext/nchar/nvarchar'.".
What am I missing here? Pseudo Code below...
Code:
--I run code in a test block like below and it appears to work!
--Same "exact" code in an SP fails and error message appears.
--TRUNCATE TABLE Prohibited per DBA for security reasions
-- Delete in Batches Only Alternative!
DECLARE @LoopCnt INT
DECLARE @BatchSize INT
DECLARE @CurRowCount INT
DECLARE @LCAT NVARCHAR(4)
DECLARE @SQL NVARCHAR(2000)
SET @LCAT = 'R1D1' -- Passed into SP normally and will change!
SET @CurRowCount = 0
SET @BatchSize = 25000
SET @SQL = N'SELECT @CurRowCount = COUNT(*) FROM ADATA.tblData_' + @LCAT
PRINT @SQL
PRINT @CurRowCount
EXEC sp_executesql
@query = @SQL,
@params = N'@CurRowCount INT OUTPUT',
@CurRowCount = @CurRowCount OUTPUT
--HERE IS WHERE IT BOMBS OUT!
PRINT @CurRowCount
--Code to Delete in Loop!!!
--SET @LoopCnt = CEILING(@CurRowCount/@BatchSize) + 1
---- Loop and delete records in small bits till the LoopCnt ends.
--WHILE @LoopCnt > 0
-- BEGIN
-- SET @SQL = 'DELETE TOP (' + LTRIM(RTRIM(CONVERT(nvarchar(10), @BatchSize))) + ') FROM ADATA.tblData_' + @CAT + ' '
-- EXEC (@SQL)
-- SET @LoopCnt = @LoopCnt - 1
-- END
Thanks in Advance!!!
Steve Medvid
IT Consultant & Web Master