Note that there are some explanatory texts on larger screens.

plurals
  1. POType Comparisons in SQL
    primarykey
    data
    text
    <p>I've got the following bit of code as part of a SQL Query:</p> <pre><code>INSERT INTO [Database] SELECT DISTINCT @ssId FROM [Document_Map] WHERE (LabelId IN (SELECT Tokens FROM StringSplitter(@sortValue, '|', 1)) </code></pre> <p>The code works fine as long as <code>@SortValue</code> is an integer, (<code>LabelId</code> is an int as well) or integers separated by the delimiter character (e.g., SortValue 420|421| compares against 420 and 421). However, I'm adding functionality which involves non-integer values for <code>@sortValue</code>. E.g.: <code>420|ABC|421|</code> <em>should</em> compare against 420, ABC, and 421.</p> <p>No worries, I thought. I'll just modify the last line of that query!</p> <pre><code>(LabelId IN (SELECT Tokens FROM StringSplitter(@sortValue, '|', 1)) OR StringId IN (SELECT Tokens FROM StringSplitter(@sortValue, '|', 1))) </code></pre> <p>Unfortunately, whenever I feed in <code>@sortValue</code> with characters in it, I get an error. It never made it to the far side of the <code>or</code>.</p> <p>After much mucking around, I finally determined that SQL is casting the string results from the StringSplitter function to compare against LabelId. No problem when the string results were guaranteed to contain only numeric characters, but SQL refuses to cast (understandably) the non-numeric string to an int, throwing out an error.</p> <p>What's the easiest way to get around this error while maintaining desired functionality? Due to database interaction, I am not sure if changing the type of <code>LabelId</code> is a viable option.</p>
    singulars
    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