Sqlserver
 sql >> Teknologi Basis Data >  >> RDS >> Sqlserver

cara mendapatkan data dari html di kolom SQL Server

Jika HTML Anda memang sesuai dengan XHTML, dan jika Anda menyimpan HTML dalam XML kolom di tabel SQL Server Anda, maka Anda dapat mengambil label darinya di T-SQL menggunakan XQuery:

DECLARE @HtmlTbl TABLE (ID INT IDENTITY, Html XML)

INSERT INTO @HtmlTbl(Html) VALUES('<ektdesignns_choices ektdesignns_nodetype="element" title="How many gigs do you play each month?" ektdesignns_caption="How many gigs do you play each month?" name="ektpoll1303074024421" ektdesignns_name="ektpoll1303074024421" id="ektpoll1303074024421">
  <ol contenteditable="false" onkeypress="design_validate_choice(1, -1, this, ''Options are required.'')" onclick="design_validate_choice(1, -1, this, ''Options are required.'')" onblur="design_validate_choice(1, -1, this, ''Options are required.'')" ektdesignns_validation="choice-req" ektdesignns_maxoccurs="1" ektdesignns_minoccurs="1" unselectable="on" title="How many gigs do you play each month?" class="design_list_vertical">
    <li>
      <input type="radio" ektdesignns_nodetype="item" name="ektpoll1303074024421" value="1 or fewer_1" title="1 or fewer" id="ID2504263" />
      <label contenteditable="true" unselectable="off" for="ID2504263">1 or fewer</label>
    </li>
    <li>
       <input type="radio" ektdesignns_nodetype="item" name="ektpoll1303074024421" value="2-4_2" title="2-4" id="ID5115606" />
       <label contenteditable="true" unselectable="off" for="ID5115606">2-4</label>
    </li>
    <li>
        <input type="radio" ektdesignns_nodetype="item" name="ektpoll1303074024421" value="5-7_3" title="5-7" id="ID477116" />
        <label contenteditable="true" unselectable="off" for="ID477116">5-7</label>
    </li>
    <li>
        <input type="radio" ektdesignns_nodetype="item" name="ektpoll1303074024421" value="8 or more_4" title="8 or more" id="ID5515606" />
        <label contenteditable="true" unselectable="off" for="ID5515606">8 or more</label>
    </li>
  </ol></ektdesignns_choices><input type="submit" value="Vote" />')

Ini akan mengambil semua <label> elemen dari (X)Html Anda sebagai string XML tunggal:

SELECT
    Html.query('//label')
FROM @HtmlTbl 
WHERE ID = 1

Keluaran:

<label contenteditable="true" unselectable="off" for="ID2504263">1 or fewer</label>
<label contenteditable="true" unselectable="off" for="ID5115606">2-4</label>
<label contenteditable="true" unselectable="off" for="ID477116">5-7</label>
<label contenteditable="true" unselectable="off" for="ID5515606">8 or more</label>

Atau ini akan memilih semua isi <label> tag, satu per baris:

SELECT
    C.value('(.)[1]', 'varchar(1000)')
FROM @HtmlTbl 
CROSS APPLY Html.nodes('//label') AS T(C)
WHERE ID = 1

Keluaran:

1 or fewer
2-4
5-7
8 or more


  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. CAST(DATETIME AS DATE) melalui klausa WHERE

  2. Kesalahan Umum DBA di MS SQL Server

  3. Apa pengaturan SQL Server terbaik untuk lingkungan pengembangan?

  4. Perbedaan antara database dan skema

  5. Bandingkan Kolom Di Mana Satu Mirip dengan Bagian Lain