Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is not how the <code>IN</code> operator works, see <a href="http://msdn.microsoft.com/en-US/library/ms177682%28v=SQL.90%29.aspx" rel="nofollow">msdn</a>. You say that weeklyfreq is of type nvarchar, so this seems to contain a comma-separated list of the values you want to check against. Otherwise I couldn't see a reason why you'd limit the subquery to a single row. For the IN operator to work the column would have to be of type int as well.</p> <p>What could work in this case:</p> <pre><code>SELECT * FROM Alerts WHERE N'%' + cast(DATEPART(dw, GETDATE()) as nvarchar(2)) + N'%' LIKE (SELECT weeklyfreq FROM Alerts WHERE Id = 1) </code></pre> <p>This assumes that weeklyfreq contains a series of one-digit numbers. Also, this will only work as long as the subquery returns only a single row. The current day of week is converted to varchar and enclosed in '%' to make the <code>LIKE</code> operator work.</p> <p>But I would not recommend to use this; if you can, store your data in a different way that allows for easier analysis.</p> <p>Also, I can't quite see where exactly you're going with this. For this to make any sense, the Alerts table of the outer select should be either referenced in the WHERE clause or within the subquery (that would then be a <a href="http://msdn.microsoft.com/en-us/library/ms187638.aspx" rel="nofollow">correlated subquery</a>).</p> <p>The only thing I can see that'd make sense is to lose the subquery, then it'd be</p> <pre><code>SELECT * FROM Alerts WHERE weeklyfreq LIKE N'%' + cast(DATEPART(dw, GETDATE()) as nvarchar(2)) + N'%' </code></pre> <p>This you can additionally filter for an user's ID by adding to the WHERE clause.</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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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