I am using SQL Server 2014. I want to update one column, then after this column use in second update statement in dynamically generated query.
My query looks like this:
declare @squery varchar(max)
set @squery = 'if('+CHAR(39)+@AppendType+CHAR(39)+' = ''Address'')
begin
update tblchild set name=(REPLACE(LEFT(phone,2)+LEFT(a,1),' ',''))
update a set a.a=a.name,a.name = b.name,a.email= b.email,a.b = '1' from tblchild as a , tblmaster as b where a.phone = b.phone
update a set a.name = b.name,a.phone = b.phone,a.a=b.a,a.b = '1' from tblchild as a , tblmaster as b where a.email = b.email and (a.b IS NULL or a.b = '')
end'
print(@squery)
exec (@squery)
select * from tblchild
but this is not working.
My table looks like this:
name email phone a b
----------------------------------------------
s [email protected] 111 NULL 1
u [email protected] 222 NULL 1
x qww 333 NULL 1
ik [email protected] 1234567890 NULL 1
kinjal [email protected] 7894561230 NULL 1