sql server - sql query to delete and return message -


i want write thing query:

begin  declare @unaloacte varchar(200); declare @total int; declare @flag int;  set @unaloacte =( select count(pd.propertydetailid) propertydetail pd join  sitedetail sd on pd.sitedetailid=sd.sitedetailid  pd.customerid<1 , pd.sitedetailid=27);  set @total= (select count(propertydetailid) total_count propertydetail sitedetailid=27) ;  if( @unaloacte = @total) delete , display message print"delete"; else  print"not able delete"  end 

i hope understand problem.

you can try this:

declare @msg varchar(200)  if( @unaloacte = @total) begin begin tran  delete   select @msg = cast(@@rowcount varchar(10)) + ' deleted' raiserror (@msg, 0, 1) nowait  commit end  else begin select 'not able delete' end 

also recommend use begin tran , commit if going use in production.


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -