Click here to Skip to main content
15,890,717 members
Home / Discussions / Database
   

Database

 
AnswerRe: Update existing and next incoming entries in SQL server 2008 Pin
Richard MacCutchan26-May-16 21:24
mveRichard MacCutchan26-May-16 21:24 
AnswerRe: Update existing and next incoming entries in SQL server 2008 Pin
Eddy Vluggen26-May-16 23:44
professionalEddy Vluggen26-May-16 23:44 
QuestionError in SQL backup with checksum Pin
IT - Researcher23-May-16 1:30
IT - Researcher23-May-16 1:30 
AnswerRe: Error in SQL backup with checksum Pin
Richard Deeming23-May-16 2:06
mveRichard Deeming23-May-16 2:06 
GeneralRe: Error in SQL backup with checksum Pin
srikrishnathanthri26-May-16 21:16
srikrishnathanthri26-May-16 21:16 
GeneralRe: Error in SQL backup with checksum Pin
Richard Deeming27-May-16 0:09
mveRichard Deeming27-May-16 0:09 
GeneralRe: Error in SQL backup with checksum Pin
Richard Deeming27-May-16 3:15
mveRichard Deeming27-May-16 3:15 
QuestionIncorrect syntax near the keyword 'CROSS'. Pin
Vimalsoft(Pty) Ltd22-May-16 1:26
professionalVimalsoft(Pty) Ltd22-May-16 1:26 
Good Day All

i have been using the below declared Cursor from the Stored-procedure for around 3 years now. The last couple of weeks i have been getting the error

Incorrect syntax near the keyword 'CROSS'.


I dont have a Cross Join in this Cursor and this started after Infrastructures upgraded the hardware on the SQL Server , i noticed other settings were lost but was able to recover them.
SQL
USE [DBPS]
GO
/****** Object:  StoredProcedure [dbo].[DATABASE_MAINTANANCE_PLAN]    Script Date: 5/22/2010 12:32:30 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*THIS SP WILL REBUILT ALL THE INDEXES IN ALL TABLES IN ALL DATABASES
THIS WILL BE CALLED FROM AN SSIS PACKAGE. THIS WILL USED IN CLIENTS TO REBUILT INDEXES AND IT WILL BE
RAN EVERY FRIDAY NIGHT
*/

ALTER PROC [dbo].[DATABASE_MAINTANANCE_PLAN]
AS 
DECLARE @DatabaseName SYSNAME   =  DB_NAME(),  @TableName VARCHAR(256) 
DECLARE @FILLFACTOR INT = 85
DECLARE @DynamicSQL NVARCHAR(max) =
 'DECLARE curAllTablesInDB CURSOR FOR SELECT TABLE_SCHEMA +
 ''.'' + TABLE_NAME AS TABLENAME  
 FROM ' + @DatabaseName + '.INFORMATION_SCHEMA.TABLES WHERE
 TABLE_TYPE = ''BASE TABLE'''  

BEGIN 
  EXEC sp_executeSQL @DynamicSQL  -- create tables cursor
  OPEN curAllTablesInDB  
  FETCH NEXT FROM curAllTablesInDB INTO @TableName  
  WHILE (@@FETCH_STATUS = 0) 
  BEGIN  
       SET @DynamicSQL = 'ALTER INDEX ALL ON ' + @TableName +
         ' REBUILD WITH (FILLFACTOR = ' + CONVERT(VARCHAR,@FILLFACTOR) + ')' 
       PRINT @DynamicSQL
       -- ALTER INDEX ALL ON Purchasing.ShipMethod REBUILD WITH (FILLFACTOR = 85)
       EXEC sp_executeSQL @DynamicSQL 
       FETCH NEXT FROM curAllTablesInDB INTO @TableName  
   END   -- cursor WHILE
   CLOSE curAllTablesInDB  
   DEALLOCATE curAllTablesInDB 
END

Thanks
Vuyiswa Maseko,

Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.

C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vimalsoft.com
vuyiswa[at]vimalsoft.com

AnswerRe: Incorrect syntax near the keyword 'CROSS'. Pin
Vimalsoft(Pty) Ltd22-May-16 2:06
professionalVimalsoft(Pty) Ltd22-May-16 2:06 
SuggestionRe: Incorrect syntax near the keyword 'CROSS'. Pin
Richard Deeming23-May-16 2:02
mveRichard Deeming23-May-16 2:02 
QuestionError in MsHflexGrid for rowcolchange event Pin
srikrishnathanthri19-May-16 0:36
srikrishnathanthri19-May-16 0:36 
AnswerRe: Error in MsHflexGrid for rowcolchange event Pin
Simon_Whale19-May-16 0:40
Simon_Whale19-May-16 0:40 
AnswerRe: Error in MsHflexGrid for rowcolchange event Pin
Mycroft Holmes20-May-16 11:51
professionalMycroft Holmes20-May-16 11:51 
QuestionAuto update SQL table entries using foreign keys Pin
srikrishnathanthri16-May-16 21:50
srikrishnathanthri16-May-16 21:50 
AnswerRe: Auto update SQL table entries using foreign keys Pin
Richard Deeming17-May-16 1:26
mveRichard Deeming17-May-16 1:26 
GeneralRe: Auto update SQL table entries using foreign keys Pin
srikrishnathanthri17-May-16 2:04
srikrishnathanthri17-May-16 2:04 
GeneralRe: Auto update SQL table entries using foreign keys Pin
Richard Deeming17-May-16 2:15
mveRichard Deeming17-May-16 2:15 
GeneralRe: Auto update SQL table entries using foreign keys Pin
srikrishnathanthri17-May-16 2:40
srikrishnathanthri17-May-16 2:40 
GeneralRe: Auto update SQL table entries using foreign keys Pin
Richard Deeming17-May-16 2:43
mveRichard Deeming17-May-16 2:43 
GeneralRe: Auto update SQL table entries using foreign keys Pin
srikrishnathanthri18-May-16 1:33
srikrishnathanthri18-May-16 1:33 
GeneralRe: Auto update SQL table entries using foreign keys Pin
Richard Deeming18-May-16 1:40
mveRichard Deeming18-May-16 1:40 
AnswerRe: Auto update SQL table entries using foreign keys Pin
John C Rayan18-May-16 2:51
professionalJohn C Rayan18-May-16 2:51 
QuestionINSERT from SELECT into a variable Pin
Jassim Rahma15-May-16 6:05
Jassim Rahma15-May-16 6:05 
AnswerRe: INSERT from SELECT into a variable Pin
Kornfeld Eliyahu Peter15-May-16 6:59
professionalKornfeld Eliyahu Peter15-May-16 6:59 
GeneralRe: INSERT from SELECT into a variable Pin
Jassim Rahma15-May-16 10:29
Jassim Rahma15-May-16 10:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.