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  | 
                             
                            
                                    | 
                                         Nerix 
                                        Starting Member 
                                         
                                        
                                        1 Post  | 
                                        
                                        
                                            
                                            
                                             Posted - 2013-04-30 : 15:38:19
                                            
  | 
                                             
                                            
                                            | Hi allI am in the middle of doing some error handling with try-catch. But I have a scenario where tthe sql server dors not throw an error when assigning a value whoch is larger than the variable can handle. Example when my variable is set to nvarchar(255) and I try to assign it with value larger or longer than 255 characters long.Below I have provided a simplified edition of my problem.-----Declare @value_a nvarchar(255)Declare c_cursor cursor forSelect name from table_aOpen c_cursorFetch next from c_cursor into@value_aWhile @@fetch_status = 0Begin try	Print @value_a. --This value can be larger than 255 characters	Print len(@value_a)	Fetch next from c_cursor into	@value_aEnd  tryBegin catch	Print 'value too long'End catch-----I expected that the sqlserver will throw an error when it tries to assigns or puts a larger value into the variable @value_a. But it is not doing that. Instead it just trims/cuts the value of to 255 characters and put that part into the variable.Are there anyway that I can force the sqlserver to throw an error instead of letting it do the auto trimming/cutting stuff?I know I can do some manual stuff by checking on the length, but as my real example contains more than twenty columns and variables it will be clumsy and bad coding.Hope you guys can help me out. | 
                                             
                                         
                                     | 
                             
       
                            
                       
                          
                            
                                    | 
                                     Lamprey 
                                    Master Smack Fu Yak Hacker 
                                     
                                    
                                    4614 Posts  | 
                                    
                                      
                                        
                                          
                                           
                                            Posted - 2013-04-30 : 16:51:35
                                          
  | 
                                         
                                        
                                          | No way that I know of, other than to check the length of things and taqke action accordingly.  | 
                                         
                                        
                                            | 
                                         
                                       
                                     | 
                                   
                            
                            
                                | 
                                    
                                      
                                     
                                    
                                 | 
                             
                         
                     | 
                 
             
         |