I have an document where i need to look to see if an element exists and has data.
So i use @xml.exist and @xml.value to first check it exists and then if it has a value.
I need to do this with 50 or so elements so i would like to write a function that does both tests. This will make my code a bit easier to read.
So i have tried but there is something wrong with it as it always says there is a value. Maybe it is not possible to do this. Here is my function. Can anyone see what is wrong with it?
alter FUNCTION pharos_Exists
-- Add the parameters for the function here
-- Declare the return variable here
declare @exists int ;
set @exists = 1 ;
if (@xml.exist( 'sql:variable("@variable")' ) = 0) or (@xml.value( 'sql:variable("@variable")', 'nvarchar(100)') = '')
set @exists = 0 ;
-- Return the result of the function