Abraham Olatubosun

Abraham Olatubosun

  • NA
  • 471
  • 114.8k

How to Select a Record and use the result to Update

Dec 16 2016 8:51 AM
Dear Code Masters,
This your humble disciple again, humbling saying thank you for all the suggestions and tips that had made my coding improving by the day.
 
My masters i have a challenge with Stored Procedure, I want to write within my stored procedure an SQL statement that will do the following :
 
  1. Create Procedure InsertDocument  
  2. (  
  3.     @Category nvarchar(1000),  
  4.     @FileName nvarchar(1500),  
  5.     @ContentType Nvarchar(1500),  
  6.     @Data varbinary(MAX),  
  7.     @Description nvarchar(2000)  
  8. )  
  9. AS  
  10. BEGIN  
  11. Declare @mTerm nvarchar(2000)  
  12.     SET NOCOUNT ON;  
  13.       
  14.     set @mTerm ="SELECT Description FROM  tbl_ElementalCostingRate  WHERE Description = "+@Description  
  15. exec @mTerm   
  16. IF (@mTrerm IS NOT Null)  
  17. UPDATE tbl_ElementalCostingRate SET Category=@Category, [fileName]=@FileName,ContentType=@ContentType,mBtye =@Data ,[Description] =@Description  
  18.  WHERE [Description] =@Description  
  19. ELSE  
  20. INSERT INTO tbl_ElementalCostingRate (Category,[fileName],ContentType,mBtye,[Description])   
  21.  VALUES(@Category,@FileName,@ContentType,@data,@Description)  
  22.   
  23. END  
  24.       
  25. END  
I am finding it difficult as i keep getting error any time i rewrite it and try so that is my challenge .
 
I will appreciate any help to resolve this issue and i will also want any like where i can get tutorial to write such Batch SQL statement like this.
 
Thank you 

Answers (1)