Sqlserver
 sql >> डेटाबेस >  >> RDS >> Sqlserver

SQL सर्वर में एकल पंक्तियों से कई तार कैसे निकालें?

स्ट्रिंग्स को अलग करने के लिए आप एक सीटीई का पुनरावर्ती रूप से उपयोग कर सकते हैं।

declare @T table (id int, [text] nvarchar(max))

insert into @T values (1, 'Peter (example@sqldat.com) and Marta (example@sqldat.com) are doing fine.')
insert into @T values (2, 'Nothing special here')
insert into @T values (3, 'Another email address (example@sqldat.com)')

;with cte([text], email)
as
(
    select
        right([text], len([text]) - charindex(')', [text], 0)),
        substring([text], charindex('(', [text], 0) + 1, charindex(')', [text], 0) - charindex('(', [text], 0) - 1) 
    from @T
    where charindex('(', [text], 0) > 0
    union all
    select
        right([text], len([text]) - charindex(')', [text], 0)),
        substring([text], charindex('(', [text], 0) + 1, charindex(')', [text], 0) - charindex('(', [text], 0) - 1) 
    from cte
    where charindex('(', [text], 0) > 0
)
select email
from cte

परिणाम

email
example@sqldat.com
example@sqldat.com
example@sqldat.com


  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. SQL इंजेक्शन को रोकने के दौरान उपयोगकर्ता को टेबल नाम और कॉलम नाम पास करने की अनुमति देना

  2. MS SQL सर्वर में 24/7 IS डेटाबेस का शेड्यूल्ड रखरखाव

  3. SQL सर्वर एकत्रीकरण के साथ यादृच्छिक (या पहले) मान चुनें

  4. SQL में पंक्तियों को कॉलम में बदलें

  5. SQL सर्वर लेनदेन संबंधी प्रतिकृति मुद्दे