Please start any new threads on our new 
    site at https://forums.sqlteam.com.  We've got lots of great SQL Server
    experts to answer whatever question you can come up with.
    
        | 
                
                    | 
                            
                                | Author | Topic |  
                                    | maccaPosting Yak  Master
 
 
                                        146 Posts | 
                                            
                                            |  Posted - 2005-06-15 : 09:08:48 
 |  
                                            | I am using the below code within a Stored Procedure to see if a number exists in a column in a table and depending on whether it does or not I am doing an Insert.Problem is I keep getting this error message when I try to save the Stored Procedure "Incorrect syntax near '=', Incorrect syntax near the keyword 'Else'".Anyone any ideas what the problem is?Thanks macca.IF EXISTS (SELECT @tempNum = Num FROM GenNum WHERE @serOff = SO)	BEGIN		SET @tempNumTwo = @tempNum + 1		INSERT INTO GenNum(SO, Num)		VALUES(@serOff,@tempNumTwo)	ENDELSE	BEGIN		INSERT INTO GenNum(SO, Num)		VALUES(@serOff,@tempNum)	END |  |  
                                    | madhivananPremature Yak Congratulator
 
 
                                    22864 Posts | 
                                        
                                          |  Posted - 2005-06-15 : 09:27:20 
 |  
                                          | Replace @tempNum = Num by Num =@tempNum and @serOff = SO by SO=@serOff MadhivananFailing to plan is Planning to fail |  
                                          |  |  |  
                                    | RMYak Posting Veteran
 
 
                                    65 Posts | 
                                        
                                          |  Posted - 2005-06-15 : 09:28:45 
 |  
                                          | You cannot assign value to a variable while using EXISTS. May be something like this..DECLARE @tempNum INTSELECT @tempNum = Num FROM GenNum WHERE SO = @serOffINSERT GenNum(SO, Num)SELECT @serOff, CASE WHEN @tempNum IS NULL THEN NULL ELSE @tempNum + 1 END |  
                                          |  |  |  
                                    | maccaPosting Yak  Master
 
 
                                    146 Posts | 
                                        
                                          |  Posted - 2005-06-15 : 09:51:20 
 |  
                                          | Thanks Madhivanan.That worked. |  
                                          |  |  |  
                                |  |  |  |