home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.databases.ms-sqlserver      Notorious Rube Goldberg contraption      19,505 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 18,816 of 19,505   
   JAW to All   
   Purge Utility   
   13 Feb 13 12:44:32   
   
   From: jwilliam@aglresources.com   
      
   I have written a PURGE utility SPROC that works fine on simple SQL.   
      
   I am trying to compose complex SQL.   
      
   delete from PurgeUtility where TableName = 'TAB1'   
      
   INSERT INTO [DB].[dbo].[PurgeUtility]([TableName],[PurgeRange])   
   VALUES ('TAB1','BA IN (SELECT BA  FROM  [TAB1].[dbo].[ACCT] (nolock) WHERE    
   OFFICE > '  + '''001''' + '  OR  TYPE > 5)');   
      
      
   TableName	PurgeRange   
   TAB1	BA IN (SELECT BA  FROM  [DB].[dbo].[ACCT] (nolock) WHERE  OFFICE > '001'    
   OR  TYPE > 5)   
      
   Block of the code code   
      
   I use the table name in the PurgTable to generate the WHERE clause for the   
   remainder of code.   
      
   BEGIN TRY   
   		 -- Load the data critera of rows (TABLOCK required for MINIMAL LOG)   
   REP_TABLE   
   		 SET   @VSQLQuery = 'REP_' + @I_TABLE   
   		 PRINT 'Fill REP Table=' + @VSQLQuery + ' Time='  + cast(getdate() as   
   varchar)   
            SET   @VSQLQuery = 'INSERT INTO ' + @VSQLQuery + ' WITH (TABLOCK)   
   SELECT * FROM TEMP_' + @I_TABLE+ ' WHERE ' + @VParameterDefinition   
   		 PRINT '===================================================='	   
   		 PRINT @VSQLQuery   
   		 PRINT '===================================================='	   
            IF @I_MODE = 'SIMULATE'   
   		  BEGIN   
   		   PRINT 'Simulation mode this step is skipped'   
   		   PRINT '===================================================='   
             END   
   		 ELSE   
   		  BEGIN   
   		   EXECUTE (@VSQLQuery)   
    	       SELECT @Vcount = @@ROWCOUNT   
   		   PRINT 'Rows Loaded to ' + @VSQLQuery + ' = ' + CAST(@Vcount AS   
   VARCHAR(10))   
   		   PRINT '===================================================='	   
   	     END   
   		End TRY   
      
   When I run code with the apostrophes like the above I get an error saying that   
   a syntax error exists.   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca