Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5939933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:53:51+00:00 2026-05-22T15:53:51+00:00

I know the datepart is returned as an int. The string lives in WeeklyFreq

  • 0

I know the datepart is returned as an int. The string lives in WeeklyFreq column with nvarchar data type in the Alerts table.

I’ve tried every variation of cast and convert, but to no avail. The Google has let me down as well.

I’m missing something that must be very obvious here. Any help would be greatly appreciated.

SELECT *
FROM Alerts
WHERE DATEPART(dw, GETDATE()) IN 
(SELECT WeeklyFreq
FROM Alerts
WHERE Id = 1)

Thank you both very much for your input. The solution seems to be:

SELECT     *
FROM         Alerts
WHERE     ((SELECT     WeeklyFreq
FROM         Alerts
WHERE     Id = 1) LIKE 
N'%' + CAST(DATEPART(dw, GETDATE()) AS  nvarchar(2)) + N'%')

I agree that storing the data in separate columns rather than in a string would be the proper solution, but circumstances don’t allow for that at this juncture.

How do I accept both of your answers as the best choice?

The big picture looks like this:

CREATE PROCEDURE [dbo].[usp_QueueOrdersWeeklyBetween] AS
DECLARE @Id int
DECLARE @VendorId int
DECLARE @SurveyId int
DECLARE @DealerId int
DECLARE @ItemId int
DECLARE @Email nvarchar(255)
DECLARE Transaction_Cursor CURSOR FOR
SELECT     Orders.Id, Orders.VendorId, Orders.SurveyId, Orders.DealerId,  Orders.ItemId, Retailers.Email
FROM         Orders INNER JOIN
                  Retailers ON Retailers.DealerId = Orders.DealerId INNER JOIN
                  Alerts ON Alerts.VendorId = Orders.VendorId
WHERE     (Orders.Queued = 0) AND (Orders.SurveyQueued = 0) AND (Alerts.Occurs = 3) AND (DATEPART(hh, GETDATE()) BETWEEN 
                  Alerts.WeeklyDailyFreqEveryStart AND Alerts.WeeklyDailyFreqEveryEnd - 1) AND (Alerts.Alert1 = 1) AND (Alerts.WeeklyDailyFreq = 2) AND 
                  (Alerts.WeeklyFreq LIKE N'%' + CAST(DATEPART(dw, GETDATE()) AS nvarchar(2)) + N'%')
OPEN Transaction_Cursor
FETCH NEXT FROM Transaction_Cursor
INTO @Id, @VendorId, @SurveyId, @DealerId, @ItemId, @Email
WHILE @@FETCH_STATUS = 0
BEGIN
INSERT INTO MailQueue (OrderId, VendorId, SurveyId, DealerId, ItemId, MailedTo, WhenQueued) 
VALUES (@Id, @VendorId, @SurveyId, @DealerId, @ItemId, @Email, GetDate())
UPDATE Orders SET Queued = 1 WHERE ID = @Id
FETCH NEXT FROM Transaction_Cursor
INTO @Id, @VendorId, @SurveyId, @DealerId, @ItemId, @Email
END
CLOSE Transaction_Cursor
DEALLOCATE Transaction_Cursor
GO
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T15:53:52+00:00Added an answer on May 22, 2026 at 3:53 pm

    This is not how the IN operator works, see msdn. 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.

    What could work in this case:

    SELECT * FROM Alerts
      WHERE N'%' + cast(DATEPART(dw, GETDATE()) as nvarchar(2)) + N'%' LIKE 
      (SELECT weeklyfreq FROM Alerts WHERE Id = 1)
    

    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 LIKE operator work.

    But I would not recommend to use this; if you can, store your data in a different way that allows for easier analysis.

    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 correlated subquery).

    The only thing I can see that’d make sense is to lose the subquery, then it’d be

    SELECT * FROM Alerts
      WHERE weeklyfreq LIKE N'%' + cast(DATEPART(dw, GETDATE()) as nvarchar(2)) + N'%'
    

    This you can additionally filter for an user’s ID by adding to the WHERE clause.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that I can do something like $int = (int)99; //(int) has a
I know how to look up this week number: (SELECT DATEPART(wk, GETDATE())) I need
I have a table in SQL Server 2005 which has three columns: id (int),
I've got a table with a date column, where a user input will be
Know anybody something about hooking __usercall type of functions? I hooking successfully __thiscall ,
Know of an OCAML/CAML IDE? Especially one that runs on Linux?
Know of any good libraries for this? I did some searches and didn't come
I know in certain circumstances, such as long running processes, it is important to
I know Microsoft has made efforts in the direction of semantic and cross-browser compliant
Anyone know if it's possible to databind the ScaleX and ScaleY of a render

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.