How do i go about insert an int parameter into a xml modify insert statement here is am example:
DECLARE @holdxml xml
DECLARE @myInt xml
set @myInt = 10
SET @holdxml = (SELECT CAST(VehicleManufacturerXML as xml) FROM VehicleManufacturers WHERE VehicleManufacturerID = 496);
SET @holdxml.modify('insert <VehicleManufacturerID>cast(@myInt, varchar(max))</VehicleManufacturerID> into (/VehicleManufacturers)[1]')
select @holdxml as x
ive tried convert, cast even found sql:variable but nothing seems to work? 🙁
In SQL Server 2008 (and that’s one of the very few new XML related features, I believe), you could write something like:
but I’m afraid in 2005, this won’t work (yet), AFAIK. Using the sql:variable in a “insert” XML DML statement is new in SQL Server 2008. You can use sql:variable in other places (e.g.
replace value ofand others) as of SQL Server 2005 and up.Marc
PS: okay, so in 2005, I’m not 100% sure if this will work (don’t have 2005 at hand anymore to test it), but you could try:
Just make your
@myIntvariable a VARCHAR(MAX) and concatenate together the string in the .modify statement.