2
Answers

How can i INSERT a @@rowcount in a table camp

Hi, I have a @@rowcount value catch from a Delete sentence, i need to INSERT that value in a table varchar column.
 
I WROTE this Query:
 
declare @delete int
delete from TableName1
select @delete = @@rowcount
 
insert into TableName2 (nom_tab, Reg_deleted)
values ('TableName1','@@rowcount');
 
BUT:
 
it only insert the WORD  "@@rowcount" and NOT THE VALUE
 
Answers (2)
1
Rupesh Kahane

Rupesh Kahane

100 19.1k 4.2m 6y
Try this is working fine without error 
 
  1. if OBJECT_ID('tempdb..#Employee'is not null  
  2. Begin  
  3. Drop Table #Employee  
  4. End   
  5.   
  6.   
  7.   
  8. if OBJECT_ID('tempdb..#Employee1'is not null  
  9. Begin  
  10. Drop Table #Employee1  
  11. End   
  12.   
  13.   
  14. CREATE TABLE #Employee  
  15. (  
  16. EmpId int,  
  17. EmpName varchar(100)  
  18. )  
  19. Insert Into #Employee values(1,'Rupesh')  
  20. Insert Into #Employee values(2,'Ashish')  
  21. Insert Into #Employee values(3,'Amol')  
  22. Insert Into #Employee values(4,'Vinayak')  
  23. Insert Into #Employee values(5,'Shital')  
  24. GO  
  25.   
  26. declare @delete int  
  27. delete from #Employee where EmpId=5  
  28. select @delete = @@rowcount  
  29. --Select @delete  
  30.   
  31. CREATE TABLE #Employee1  
  32. (  
  33. EmpName varchar(100)  
  34. )  
  35.   
  36. Insert Into #Employee1 values(@delete)  
  37. Insert Into #Employee1 values(@@rowcount)  
  38.   
  39. Select * from  #Employee1  
 
Accepted
1
Harshad Kathiriya

Harshad Kathiriya

NA 39 4 6y
Just removed the single quote from @@rowcount when inserting the values to the table
values ('TableName1',@@rowcount);"