Note that there are some explanatory texts on larger screens.

plurals
  1. POSQL Server 2008: Run Xquery from values in database on values in database
    primarykey
    data
    text
    <p>I have a table storing multiple values that I want to use in an Xquery to find data in another table matching the results. The Xquery strings are built to return either a true or false when evaluated using <code>xmlData.Exists(value)</code>. Here is what I have so far:</p> <p>Stored Procedure:</p> <pre><code>ALTER PROCEDURE [XquerySearch] @xquery nvarchar(4000) DECLARE @sqlcmd NVARCHAR(MAX), @SafeXquery NVARCHAR(4000) SET @SafeXquery = REPLACE(@xquery, '''', '''''') SET @sqlcmd = N'SELECT d.[guid], p.pGuid, FROM Data AS d LEFT OUTER JOIN PDataLink as p on d.[guid] = p.pGuid WHERE d.xmlData.exist(''' + @SafeXquery + ''') = 1'; exec (@sqlcmd) </code></pre> <p>Above is the only way I've found to be able to run an xquery using a dynamic value as the search parameter (not the actual field being searched).</p> <p>OK, so now assuming I have another stored procedure called <code>RunQuery</code>, which is building a result set searching other parameters, such as creationDate. I can't figure out how to use the <code>XquerySearch</code> stored procedure above to provide a final result set that meets my other criteria and Xquery criteria.</p> <p>Stored Procedure:</p> <pre><code>ALTER PROCEDURE [RunQuery] @queryid int DECLARE @ideaTestingTable table ( pGuid uniqueidentifier) ~*****~ SELECT Distinct p.guid FROM Parent p LEFT OUTER JOIN PDataLink pdl ON p.[guid] = pdl.pGuid LEFT OUTER JOIN Data d ON pdl.dataGuid = d.[guid] CROSS JOIN QueryParams q WHERE q.id = @queryid AND ~My other search parameters are true~ AND ~*****~ </code></pre> <p>~<strong><em>*</em>****</strong>~ = How can I either build up a temp table that with a list of <code>pGuid</code> that have matching <code>d.xmlData</code> under them (possibly calling the XquerySearch stored procedure) to then add into the <code>where</code> at the bottom <code>AND p.[guid] IN @ideaTestingTable</code> or some way to run the xquery directly from the where clause.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload