use xmldb
go

drop function OverPricedItems
go

-- overpriced items
create function OverPricedItems(@price money, @theid int)
returns xml
as
begin
 declare @x as xml
 select @x = invoice::query('
    (: XQuery program :)

  ') 
 from xmlinvoice
 where id = @TheID
 return @x
end
go

declare @x as xml
set @x = dbo.OverPricedItems(5.00, 1)
print cast(@x as varchar(max))
go

-- SQL Query
select id, invoice::query('
    (: XQuery program :)
  ') 
from xmlinvoice
