Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
JosephBaggett
Starting Member
1 Post |
Posted - 2008-12-14 : 09:23:42
|
| I am doing a query that passes in xml data.I have a parameter @DressCodeList xml.The xml being passed in looks like this:'<DressCodeList><DressCode><DressCodeId>1</DressCodeId></DressCode></DressCodeList>'I declare the inside the stored proc this:declare @xmlDressCodeDocument intExec sp_xml_preparedocument @xmlDressCodeDocument OUTPUT, @DressCodeListI have a CTE I need to join with itWITH DressCodeListAS(SELECT DressCodeName, DressCodeDescriptionFROM DressCodeInner JOIN OPENXML(@xmlDressCodeDocument,''DressCodeList/DressCode'', 2) WITH( xmlDressCodeId int ''./DressCodeId'' )As XmlDressCodeDocumentON [DressCode].DressCodeId = [XmlDressCodeDocument].xmlDressCodeId)The problem is the CTE cannot allow the xml declaration at the top. What can I do? |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-12-14 : 12:25:26
|
if you're using sql 2005 use xml functions like modify(),query(),value()... to parse the data. something likeSELECT d.DressCodeName,d.DressCodeDescriptionFROM DressCode dINNER JOIN(SELECT t.u.value('./DressCodeId[1]','int') AS DressCodeIdFROM @DressCodeList.nodes('/DressCodeList/DressCode')t(u))xON x.DressCodeId=d.DressCodeId |
 |
|
|
|
|
|