snippetsqlModerate
how to test if XML = '' in sql server?
Viewed 0 times
sqlxmltesthowserver
Problem
I am working with sql server 2005 and I had a situation where many values can be passed in a parameter.
Based on this: Passing multiple values for one SQL parameter this procedure uses XML as a parameter.
here is the code of the stored procedure:
more info about this procedure here
this is an example of how it can be called:
Question:
what is the best way to find out whether or not the parameter
what if they call this procedure like this:
as it was sug
Based on this: Passing multiple values for one SQL parameter this procedure uses XML as a parameter.
here is the code of the stored procedure:
CREATE PROCEDURE [DENORMV2].[udpProductBulletPointSelectByTier1NoteTypeCode] (
@Tier1 VARCHAR(10),
@LanguageID INT,
@SeasonItemID VARCHAR(5) = NULL,
@ListNoteTypeCode XML,
@CacheDuration INT OUTPUT )
WITH EXECUTE AS 'webUserWithRW'
AS
SELECT pbp.Tier1, pbp.LanguageId, pbp.NoteText, pbp.NoteTypeCode,
pbp.NoteGroup, pbp.SortOrder
FROM dbo.ProductBulletPoint pbp
WHERE Tier1 = @Tier1
AND LanguageId = @LanguageID
AND ( SeasonItemId = @SeasonItemID
OR
@SeasonItemID is null
)
AND pbp.NoteTypeCode IN (
SELECT NoteTypeCode=BulletPoint.NoteTypeCode.value('./text()[1]', 'varchar(50)')
FROM @ListNoteTypeCode.nodes('/BulletPoint/NoteTypeCode') AS BulletPoint ( NoteTypeCode )
)
SELECT @CacheDuration = Duration
FROM dbo.CacheDuration
WHERE [Key] = 'Product'
GOmore info about this procedure here
this is an example of how it can be called:
declare @p5 int set @p5=86400
exec DenormV2.udpProductBulletPointSelectByTier1NoteTypeCode
@Tier1=N'WW099',
@LanguageID=3,
@SeasonItemID=N'16AUT',
@ListNoteTypeCode=N'GarmentCompositionFootwearAccessoryComposition',
@CacheDuration=@p5 output select @p5Question:
what is the best way to find out whether or not the parameter
@ListNoteTypeCode XML is empty?what if they call this procedure like this:
declare @p5 int set @p5=86400
exec DenormV2.udpProductBulletPointSelectByTier1NoteTypeCode
@Tier1=N'WW099',
@LanguageID=3,
@SeasonItemID=N'16AUT',
@ListNoteTypeCode=N'',
@CacheDuration=@p5 output select @p5as it was sug
Solution
You may check for
Your XPath can be more specific, if necessary:
NULL and nodes absence (exist method of xml type):@ListNoteTypeCode is NULL OR @ListNoteTypeCode.exist('*') = 0Your XPath can be more specific, if necessary:
@ListNoteTypeCode is NULL OR @ListNoteTypeCode.exist('/BulletPoint/NoteTypeCode/text()') = 0Code Snippets
@ListNoteTypeCode is NULL OR @ListNoteTypeCode.exist('*') = 0@ListNoteTypeCode is NULL OR @ListNoteTypeCode.exist('/BulletPoint/NoteTypeCode/text()') = 0Context
StackExchange Database Administrators Q#147178, answer score: 10
Revisions (0)
No revisions yet.