Skip to main content
July 10, 2009
Question

syntax near the keyword 'end'

  • July 10, 2009
  • 1 reply
  • 1952 views

Hello Guys,

Need Help!!  I recently upgrade my CF server from 4.5 to 8.0. In Production enviornment every thing is running fine but in Pre-Production I am having issue running the same code. Provided I kept same setting please if some one can help me . When I am trying to run Webreports I get message on 8.0 server. Not sure what is going so wrong that it works fine on 4.5 server but not on 8.0 server.

Page:/webreports/LineSheetFind.cfm?RequestTimeout=500
Date:Fri Jul 10 09:52:07 EDT 2009
Error:

Error Executing Database Query. [Macromedia][SQLServer JDBC Driver][SQLServer]

Incorrect syntax near the keyword 'end'.
The error occurred on line 28.

Where Linesheetfind.cfm has :

<cfquery name="qrySelect" datasource="#local_session_var_sDSN_WebPDM#" timeout="150000">  


  #Replace(mySQL," ' ' "," ' ","ALL")# (NOTE: line28 and these are single quotes ( ' ' ) in double quotes ( " ") )

</cfquery>

My SQL Query is as follow:

SET              nocount ON
                          SELECT DISTINCT FolderId
                           INTO            #TEMP1_smehboob_29
                           FROM         ((SELECT     FolderHeaders.FolderId
                                                    FROM         FolderHeaders
                                 WHERE     (FolderHeaders.Season IN (78) AND FolderHeaders.Generation IN (0, 2) AND FolderHeaders.Division3 IN (196)))
                                                  UNION
                                                  (SELECT     FolderID
                                                   FROM         FolderHeaders INNER JOIN
                                     AuxiliaryFields ON AuxiliaryDefs.FieldNumber = AuxiliaryFields.FieldNumber AND
                                                              FolderHeaders.FolderId = AuxiliaryFields.PageId
          WHERE     AuxiliaryDefs.FieldLabel = ' Reporting Seasons ' AND (', ' + AuxiliaryFields.TextValue + ', ' LIKE ' %, Fall 2009, % ') AND
             FolderHeaders.Generation IN (0, 2) AND FolderHeaders.Division3 IN (196))) AS x
SET              nocount OFF
                          SELECT DISTINCT
  FolderHeaders.FolderId AS FolderId, mAX(CASE WHEN AuxiliaryDefs.FieldLabel = ' Calendar : ' THEN isnull(AuxiliaryFields.TextValue, ' ')
                                                  ELSE ' ' END) AS OrderType, FolderHeaders.Style AS Style,
     isnull(max(CASE WHEN AuxiliaryDefs.FieldLabel = ' Active : ' THEN CASE WHEN isnull(AuxiliaryFields.yesnovalue, - 2)
                                                  = 0 THEN ' Inactive ' ELSE CASE WHEN isnull(AuxiliaryFields.yesnovalue, - 2) = - 1 THEN ' Active ' ELSE ' Active ' END END END),
                                                  ' Active ') AS Active
                           FROM         (FolderHeaders INNER JOIN
                                                  (AuxiliaryDefs INNER JOIN
                                                  (Blocks INNER JOIN
                                                  AuxiliaryFields ON Blocks.BlockType = AuxiliaryFields.BlockType) ON (AuxiliaryDefs.BlockType = Blocks.BlockType) AND
                                                  (AuxiliaryDefs.FieldNumber = AuxiliaryFields.FieldNumber)) ON (FolderHeaders.FolderId = AuxiliaryFields.PageId) AND
                                                  (FolderHeaders.FolderId = Blocks.BlockId)) INNER JOIN
                                                  #TEMP1_smehboob_29 ON FolderHeaders.FolderId = #TEMP1_smehboob_29.FolderId
                           GROUP BY FolderHeaders.FolderId, FolderHeaders.Style
                           ORDER BY FolderHeaders.Style
SET              nocount ON IF
                          (SELECT     count(name)
                            FROM          tempdb.dbo.sysobjects
                            WHERE      name LIKE ' #TEMP1_smehboob_29 % ') > 0 DROP TABLE #TEMP1_smehboob_29 IF
                          (SELECT     count(name)
                            FROM          tempdb.dbo.sysobjects
                            WHERE      name LIKE ' #TEMP2_smehboob_29 % ') > 0 DROP TABLE #TEMP2_smehboob_29 IF
                          (SELECT     count(name)
                            FROM          tempdb.dbo.sysobjects
                            WHERE      name LIKE ' #TEMP3_smehboob_29 % ') > 0 DROP TABLE #TEMP3_smehboob_29 IF
                          (SELECT     count(name)
                            FROM          tempdb.dbo.sysobjects
                            WHERE      name LIKE ' #TEMP4_smehboob_29 % ') > 0 DROP TABLE #TEMP4_smehboob_29 IF
                          (SELECT     count(name)
                            FROM          tempdb.dbo.sysobjects
                            WHERE      name LIKE ' #TEMP5_smehboob_29 % ') > 0 DROP TABLE #TEMP5_smehboob_29 IF
                          (SELECT     count(name)
                            FROM          tempdb.dbo.sysobjects
                            WHERE      name LIKE ' #TEMP6_smehboob_29 % ') > 0 DROP TABLE #TEMP6_smehboob_29 IF
                          (SELECT     count(name)
                            FROM          tempdb.dbo.sysobjects
                            WHERE      name LK 7EO '   oF

This topic has been closed for replies.

1 reply

Inspiring
July 14, 2009

First, grab that SQL statement from your code and put it into the SQL Server Manager interactive tool.  Use this to debug your SQL syntax.

Then, carefully consider putting that complicated, hard-to-read SQL statement into a stored procedure.  This removes the complicated SQL entirely from your ColdFusion code (where, arguably, it does not belong...) and puts it into a centralized, easy-to-change place within the SQL Server environment itself.  The advantages here are:

  1. Your ColdFusion code becomes much shorter and easier to read.
  2. When (not if...) the SQL configuration changes in some way, no one has to "go and find" the ColdFusion code that must be changed...  "the code that needs to be changed is right here, in the stored procedure."  SQL Server knows that the dependency exists and can point it out to you on request (a very nice thing when there are hundreds of stored-procs).
  3. SQL statements in a stored-procedure often run more efficiently.
July 14, 2009

Hello TLC ,

Thanks for the reply and I have tried pasting SQL from my code in SQL studio and it works fine in SQL studio but when I try to run it from my code have #replace# enabled at line 28 , I keep getting the message "Syntax error near END".

I would really appreciate if any one can help me or direct me at the right direction. As I said the code works fine in CF server 4.5 Production enviorn fine but some how when I upgraded it to CF server 8.0 server I am having issues running SQL quries.

Thanks for reading.