Getting Null value Of variable in sql server -
strange situation in trigger assign column value variable gives exception while inserting other table using variable.
e.g
select @srno=a.srno id=123;
insert b (srno) values (@srno) // here gives null
run above select query in query pane works fine in trigger gives me null
suggestions
alter procedure processdata
@id decimal(38,0),
@xmlstring varchar(1000),
@phone varchar(20)
as
declare
@idoc int,
@ierror int,
@serial varchar(15),
@phonenumber varchar(15),
begin
commit tran
exec sp_xml_preparedocument @idoc output,@xmlstring<br/> select @ierror = @@error<br/> if @ierror = 0<br/> begin<br/>
select @serial = convert(text,[text]) openxml (@idoc,'',1) nodetype = 3 , parentid = 2
if @serial=valid <br/> begin<br/> begin tran invalid<br/> begin try <br/> declare @phoneid decimal(38,0);<br/> select @phoneid = b.phoneid inner join b on a.id = b.id a.phonenumber '%'+@senderphone + '%'<br/> print @phoneid ; //gives null<br/> end try<br/> begin catch<br/> print error_message();<br/> end catch<br/>
you should work sets of rows in triggers, if multiple rows affected code handles rows. insert when value not null:
insert b (srno) select a.srno id=123 , a.srno not null
Comments
Post a Comment