In SQL Server 2008 (and that's one of the very few new XML related features, I believe), you could write something like:
DECLARE @holdxml xml
DECLARE @myInt xml
set @myInt = '<VehicleManufacturerID>abc</VehicleManufacturerID>'
SET @holdxml = (SELECT CAST(VehicleManufacturerXML as xml) FROM VehicleManufacturers WHERE VehicleManufacturerID = 496);
SET @holdxml.modify('insert sql:variable("@myInt") into (/VehicleManufacturers)[1]')
select @holdxml as x
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 of
and 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:
DECLARE @holdxml xml
DECLARE @myInt VARCHAR(MAX)
set @myInt = '<VehicleManufacturerID>abc</VehicleManufacturerID>'
SET @holdxml = (SELECT CAST(VehicleManufacturerXML as xml) FROM VehicleManufacturers WHERE VehicleManufacturerID = 496);
SET @holdxml.modify('insert ' + @myInt + ' into (/VehicleManufacturers)[1]')
select @holdxml as x
Just make your @myInt
variable a VARCHAR(MAX) and concatenate together the string in the .modify statement.