Most of the time we required to split the comma separated string into number of row to insert or some time use it inside the “in clause” for DML operation sql query, here is a very good example using the power of XML in SQL query you can do it very easy way. This the best split function in sql 2005/2008 to split a comma separated value or string into temp table using XML.
Step 1First of all cast the @commasepvalue into an XML data type by replacing the “,” comma delimiter with starting and ending tags ' '.
First of all cast the @commasepvalue into an XML data type by replacing the “,” comma delimiter with starting and ending tags ' '.
declare @commasepvalue varchar(50)='rashmi,ashish,punit,vishal'SELECT cast('<x>' +replace(@commasepvalue,',','</x><x>' )+'</x>' as xml) as thexml Use 'CROSS APPLY' for splitting the data. The APPLY clause lets you join a table to a table-valued-function. The APPLY clause acts like a JOIN without the ON clause and comes in two flavors: CROSS and OUTER.
* The OUTER APPLY clause returns all the rows on the left side (@commasepvalue)
SELECT cast('<x>' +replace(@commasepvalue,',','</x><x>' )+'</x>' as xml)
as thexml
Use 'CROSS APPLY' for splitting the data. The APPLY clause lets you join a table to a table-valued-function. The APPLY clause acts like a JOIN without the ON clause and comes in two flavors: CROSS and OUTER.
* The OUTER APPLY clause returns all the rows on the left side (@commasepvalue)
* The OUTER APPLY clause returns all the rows on the left side (@commasepvalue)
whether they return any rows in the table-valued-function or not. The columns that the
table-valued-function returns are null if no rows are returned.
* The CROSS APPLY only returns rows from the left side (@commasepvalue)
if the table-valued-function returns rows.declare @commasepvalue varchar(50)='rashmi,ashish,punit,vishal'select q2.value from(SELECT cast('<x>' +replace(@commasepvalue,',','</x><x>' )+'</x>' as xml) as thexml)q1 CROSS APPLY(SELECT x.value('.','varchar(100)') as value FROM thexml.nodes('x') as f(x))q2
Oupput of the Above query is
table-valued-function returns are null if no rows are returned.
* The CROSS APPLY only returns rows from the left side (@commasepvalue)
if the table-valued-function returns rows.
(SELECT cast('<x>' +replace(@commasepvalue,',','</x><x>' )+'</x>' as xml) as thexml)q1 CROSS APPLY
(SELECT x.value('.','varchar(100)') as value FROM thexml.nodes('x') as f(x))q2
Nice post but you have missed something while generating xml
ReplyDeleteSELECT cast(''+replace(@commasepvalue,',','')+'' as xml
this is the right select query to generate the xml
thanks, its done
ReplyDeleteIt is Great! Thx
ReplyDeleteSmm panel
ReplyDeletesmm panel
İs ilanlari
İnstagram takipçi satın al
hirdavatciburada.com
Www.beyazesyateknikservisi.com.tr
servis
tiktok jeton hilesi
beykoz alarko carrier klima servisi
ReplyDeleteüsküdar alarko carrier klima servisi
pendik toshiba klima servisi
pendik beko klima servisi
tuzla lg klima servisi
tuzla alarko carrier klima servisi
maltepe daikin klima servisi
kadıköy daikin klima servisi
beykoz lg klima servisi
Good content. You write beautiful things.
ReplyDeletehacklink
mrbahis
mrbahis
taksi
vbet
sportsbet
korsan taksi
hacklink
sportsbet
Good text Write good content success. Thank you
ReplyDeletetipobet
bonus veren siteler
mobil ödeme bahis
kibris bahis siteleri
betmatik
poker siteleri
kralbet
betpark
dijital kartvizit
ReplyDeletereferans kimliği nedir
binance referans kodu
referans kimliği nedir
bitcoin nasıl alınır
resimli magnet
HLQX1D
hatay
ReplyDeletekars
mardin
samsun
urfa
FWS7
https://saglamproxy.com
ReplyDeletemetin2 proxy
proxy satın al
knight online proxy
mobil proxy satın al
F5E3V
izmir
ReplyDeleteErzurum
Diyarbakır
Tekirdağ
Ankara
BMM4
Eskişehir
ReplyDeleteDenizli
Malatya
Diyarbakır
Kocaeli
MHN7
Antalya
ReplyDeleteAntep
Burdur
Sakarya
istanbul
KZ0Y
Batman
ReplyDeleteArdahan
Adıyaman
Antalya
Giresun
LLFM
goruntulu show
ReplyDeleteücretli
ZEY6
ankara parça eşya taşıma
ReplyDeletetakipçi satın al
antalya rent a car
antalya rent a car
ankara parça eşya taşıma
LQH
kırklareli evden eve nakliyat
ReplyDeleteısparta evden eve nakliyat
istanbul evden eve nakliyat
ankara evden eve nakliyat
kırıkkale evden eve nakliyat
7LBKCQ
2EE6A
ReplyDeleteŞırnak Şehirler Arası Nakliyat
Malatya Şehirler Arası Nakliyat
Manisa Şehirler Arası Nakliyat
Erzurum Parça Eşya Taşıma
Kilis Şehirler Arası Nakliyat
Afyon Evden Eve Nakliyat
Aksaray Evden Eve Nakliyat
Bayburt Şehirler Arası Nakliyat
Karabük Evden Eve Nakliyat
90F1D
ReplyDeleteBolu Şehir İçi Nakliyat
Kırıkkale Evden Eve Nakliyat
Coinex Güvenilir mi
Bitexen Güvenilir mi
Çankırı Evden Eve Nakliyat
Tekirdağ Cam Balkon
Altındağ Fayans Ustası
Kilis Parça Eşya Taşıma
Bolu Parça Eşya Taşıma
C7D46
ReplyDeletesms onay
arama motoru optimizasyonu
seo fiyatları
backlink paketleri
hacklink panel
steroid satın al
çekmeköy çilingir
hacklink fiyat
backlink
66A4E
ReplyDelete%20 binance indirim kodu
74AB5
ReplyDelete%20 indirim kodu
2C46F
ReplyDeleteSiirt Mobil Sesli Sohbet
amasya ücretsiz sohbet siteleri
Giresun Canlı Görüntülü Sohbet Uygulamaları
Bartın Görüntülü Sohbet Odaları
bursa sohbet uygulamaları
en iyi görüntülü sohbet uygulamaları
artvin kızlarla rastgele sohbet
telefonda kadınlarla sohbet
erzurum görüntülü canlı sohbet
8CDC9
ReplyDeletePi Network Coin Hangi Borsada
Bitcoin Madenciliği Nasıl Yapılır
Bitcoin Kazma
Meta Coin Hangi Borsada
Onlyfans Beğeni Hilesi
Sui Coin Hangi Borsada
Kripto Para Oynama
Parasız Görüntülü Sohbet
Ergo Coin Hangi Borsada
FGNHGNC GJ
ReplyDeleteشركة مكافحة حشرات
شركة صيانة افران بمكة etDpCp9jJj
ReplyDeleteشركة تسليك مجاري بخميس مشيط C8eTS3n3KF
ReplyDeleteشركة تنظيف بخميس مشيط XVLnVXd5Q9
ReplyDeleteشركة مكافحة حشرات بالقطيف pLUXo9Z6X1
ReplyDeleteشركة تسليك مجاري بالاحساء zvgyFognSY
ReplyDeleteشركة تنظيف خزانات بابها nIAJkFmeAi
ReplyDeleteشركة عزل اسطح بالاحساء iY12KgHLlD
ReplyDelete5DBD28EFE6
ReplyDeletetiktok beğeni satın al
شركة تنظيف سجاد بالاحساء YZjjViR50h
ReplyDeleteشركة تنظيف موكيت بجازان FRPJQga8Mu
ReplyDelete47998CD798
ReplyDeletetakipçi fiyatları
شركة تنظيف موكيت بالقطيف
ReplyDeletedqm2W9VaoR