Filter SQL result using XML

Filter SQL result using XML

I have created the following piece of code to ensure that I can filter certain dimension using a comma delimited parameter:

I have created the following piece of code to ensure that I can filter certain dimension using a comma delimited parameter:

DECLARE @Dimension NVARCHAR(MAX)

SET @Dimension = 'Average Life,Coupon Frequency'

DECLARE @XML XML SET @XML = CAST('<i>' + REPLACE(@Dimension, ',', '</i><i>') + '</i>' AS XML)

SELECT d.* FROM Dim_Security_Analytics as d

INNER JOIN @XML.nodes('i') x(i) ON d.dimension = x.i.value('.', 'NVARCHAR(MAX)')

WHERE d.Date = '2018-12-31'

However when a '' or a NULL is passed in the @Dimension parameter I would like all dimensions to be returned. I'm unsure as to how I can code for this in the XML as this is pretty new to me.

Can anyone point me in the right direction?

Thanks

t-sql sql xml

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Introduction to Structured Query Language SQL pdf

SQL stands for Structured Query Language. SQL is a scripting language expected to store, control, and inquiry information put away in social databases. The main manifestation of SQL showed up in 1974, when a gathering in IBM built up the principal model of a social database. The primary business social database was discharged by Relational Software later turning out to be Oracle.

Introduction to Structured Query Language SQL pdf

SQL stands for Structured Query Language. SQL is a scripting language expected to store, control, and inquiry information put away in social databases. The main manifestation of SQL showed up in 1974, when a gathering in IBM built up the principal model of a social database. The primary business social database was discharged by Relational Software later turning out to be Oracle.

Welcome Back the T-SQL Debugger with SQL Complete – SQL Debugger

Debug SQL stored procedures and develop your SQL database project with dbForge SQL Complete, a new add-in for Visual Studio and SSMS. When you develop large chunks of T-SQL code with the help of the SQL Server Management Studio tool, it is essential to test the “Live” behavior of your code by making sure that each small piece of code works fine and being able to allocate any error message that may cause a failure within that code.

The Easy Guide on How to Use Subqueries in SQL Server

This article provides an outlook on various types of subqueries in SQL such as select or other T-SQL statements and caveats when using them.

How to Modify a SQL Server Graph Edge with T-SQL

Learn how to modify a SQL Server Graph Edge with T-SQL. I can insert, delete, and even update graph tables using normal SQL syntax.