Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
<pre>SET @SQLString = 'DELETE MAINTABLE FROM ' + @TEMP_SALARY_DETAILS + '  AS MAINTABLE                
           JOIN(SELECT TOP 1 ID AS ID                 
             FROM  ' + @TEMP_SALARY_DETAILS + '                 
            WHERE( ' + @RS_EMPLOYEE_SERIAL_NO +  '       = '''' OR ' + @RS_EMPLOYEE_SERIAL_NO+ '        IS NULL)                
             AND ( ' + @RS_PAN_OF_THE_EMPLOYEE +  '      = '''' OR ' + @RS_PAN_OF_THE_EMPLOYEE + '      IS NULL)               
             AND ( ' + @RS_NAME_OF_THE_EMPLOYEE +  '     = '''' OR ' + @RS_NAME_OF_THE_EMPLOYEE + '     IS NULL)                
             AND ( ' + @RS_CATEGORY_OF_THE_EMPLOYEE + '  = '''' OR ' + @RS_CATEGORY_OF_THE_EMPLOYEE + ' IS NULL)'               
                            
    
     SET @SQLString += 'ORDER BY ID) AS STARTING_ID                
           ON MAINTABLE.ID >= STARTING_ID.ID'    

	EXECUTE sp_executesql @SQLString


What I have tried:

i didn't guess where it is wrong.
Posted
Updated 13-Apr-18 2:31am

1 solution

Start by using SSMS to look at exactly what you are trying to execute using a PRINT instead of EXECUTE

At a guess, one of your parameters contains a quote character, which will mess up your whole statement.

You really don't want to do that anyway - you are still leaving yourself wide open to SQL Injection attack when you concatenate strings, even inside SQL. Passing your parameters as is would be a lot safer. See here for an example: sql server - EXEC sp_executesql with multiple parameters - Stack Overflow[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900