Advertisement
Guest User

Untitled

a guest
Jul 3rd, 2015
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. declare @squery varchar(max)
  2. set @squery = 'if('+CHAR(39)+@AppendType+CHAR(39)+' = ''Address'')
  3. begin
  4. update tblchild set name=(REPLACE(LEFT(phone,2)+LEFT(a,1),' ',''))
  5. 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
  6. 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 = '')
  7. end'
  8.  
  9. print(@squery)
  10. exec (@squery)
  11.  
  12. select * from tblchild
  13.  
  14. name email phone a b
  15. ----------------------------------------------
  16. s z@a.in 111 NULL 1
  17. u a@ghf.ij 222 NULL 1
  18. x qww 333 NULL 1
  19. ik k@gmail.com 1234567890 NULL 1
  20. kinjal kin@abc.com 7894561230 NULL 1
  21.  
  22. declare @squery nvarchar(max)
  23. declare @AppendType nvarchar(max) = N'Address'
  24.  
  25. set @squery = N'if('+CHAR(39)+@AppendType+CHAR(39)+N' = ''Address'')
  26. begin
  27. update tblchild set name=(REPLACE(LEFT(phone,2)+LEFT(a,1),'' '',''''))
  28. 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
  29. 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 = '''')
  30. end'
  31.  
  32. print(@squery)
  33. execute sp_executesql @squery
  34.  
  35. select * from tblchild
  36.  
  37. update tblchild set name=(REPLACE(LEFT(phone,2)+LEFT(ISNULL(a,''''),1),'' '',''''))
  38.  
  39. update tblchild set name=(REPLACE(LEFT(phone,2)+LEFT(a,1),' ',''))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement