Guest User

Untitled

a guest
Apr 25th, 2018
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. <xml>
  2. <customer name="Max">
  3. <email address="me@you.com" />
  4. </customer>
  5. <customer name="Erik">
  6. <email address="erik@your-mom.com" />
  7. </customer>
  8. <customer name="Brent">
  9. <email address="brentcom" />
  10. </customer>
  11. </xml>
  12.  
  13. <customer name="Brent">
  14. <email address="brentcom" />
  15. </customer>
  16.  
  17. DECLARE @x XML = '<xml>
  18. <customer name="Max"><email address="me@you.com" /></customer>
  19. <customer name="Erik"><email address="erik@your-mom.com" /></customer>
  20. <customer name="Brent"><email address="brentcom" /></customer>
  21. </xml>';
  22.  
  23. SELECT WithValidEmail = @x.query('/xml/customer/email[contains(@address, "@")]')
  24. , WithInvalidEmail = @x.query('/xml/customer/email[contains(@address, "@")] = False');
  25.  
  26. ╔═══════════════════════════════════════╦══════════════════╗
  27. ║ WithValidEmail ║ WithInvalidEmail ║
  28. ╠═══════════════════════════════════════╬══════════════════╣
  29. ║ <email address="me@you.com" /> ║ ║
  30. ║ <email address="erik@your-mom.com" /> ║ false ║
  31. ╚═══════════════════════════════════════╩══════════════════╝
  32.  
  33. SELECT WithInValidEmail = @x.query('/xml/customer/email')
  34. WHERE @x.exist('/xml/customer/email[contains(@address, "@")]') = 0;
  35.  
  36. ╔══════════════════╗
  37. ║ WithInValidEmail ║
  38. ╚══════════════════╝
  39. (no results)
  40.  
  41. DECLARE @x XML
  42. = '<xml>
  43. <customer name="Max"><email address="mvernon@mvct.com" /></customer>
  44. <customer name="Erik"><email address="erik@your-mom.com" /></customer>
  45. <customer name="Brent"><email address="brentcom" /></customer>
  46. </xml>';
  47.  
  48.  
  49. SELECT x.c.value('@address', 'VARCHAR(100)') AS [email]
  50. FROM @x.nodes('/xml/customer/email') AS x(c)
  51. WHERE x.c.exist('@address[contains(., "@")]') = 0;
Add Comment
Please, Sign In to add comment