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

  • Home
  • SEARCH
  • 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 7590567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:26:00+00:00 2026-05-30T20:26:00+00:00

I have a simple question regarding T-SQL. I have a stored procedure which calls

  • 0

I have a simple question regarding T-SQL. I have a stored procedure which calls a Function which returns a date. I want to use an IF condition to compare todays date with the Functions returned date. IF true to return data.

Any ideas on the best way to handle this. I am learning t-sql at the moment and I am more familar with logical conditions from using C#.

ALTER FUNCTION [dbo].[monday_new_period](@p_date as datetime) -- Parameter to find current date
RETURNS datetime
BEGIN 

-- 1 find the year and period given the current date

-- create parameters to store period and year of given date
declare @p_date_period int, @p_date_period_year int

-- assign the values to the period and year parameters
select 
@p_date_period=period, 
@p_date_period_year = [year] 
from client_week_uk where @p_date between start_dt and end_dt

-- 2 determine the first monday given the period and year, by adding days to the first day of the period
-- this only works on the assumption a period lasts a least one week

-- create parameter to store the first day of the period
declare @p_start_date_for_period_x datetime
select @p_start_date_for_period_x = min(start_dt)
from client_week_uk where period = @p_date_period and [year] = @p_date_period_year

-- create parameter to store result
declare @p_result datetime

-- add x days to the first day to get a monday
select @p_result = dateadd(d, 
    case datename(dw, @p_start_date_for_period_x) 
        when 'Monday' then 0
        when 'Tuesday' then 6
        when 'Wednesday' then 5
        when 'Thursday' then 4
        when 'Friday' then 3
        when 'Saturday' then 2
        when 'Sunday' then 1 end,
    @p_start_date_for_period_x)

Return @p_result
END

ALTER PROCEDURE [dbo].[usp_data_to_retrieve]
-- Add the parameters for the stored procedure here

AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

IF monday_new_period(dbo.trimdate(getutcdate()) = getutcdate()

BEGIN

-- SQL GOES HERE --

END

Thanks!!

  • 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-30T20:26:01+00:00Added an answer on May 30, 2026 at 8:26 pm

    I assume you are working on Sql2008. See documentation of IF and CASE keywords for more details.

    CREATE FUNCTION dbo.GetSomeDate()
    RETURNS datetime
    AS
    BEGIN
        RETURN '2012-03-05 13:12:14'
    END
    
    GO
    
    
    IF CAST(GETDATE() AS DATE) = CAST(dbo.GetSomeDate() AS DATE)
    BEGIN
        PRINT 'The same date'
    END
    ELSE
    BEGIN
        PRINT 'Different dates'
    END
    
    -- in the select query
    SELECT CASE WHEN CAST(GETDATE() AS DATE) = CAST(dbo.GetSomeDate() AS DATE) THEN 1 ELSE 0 END AS IsTheSame
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple question and wish to hear others' experiences regarding which is
I have a simple question regarding usability. Which is the preferred way of having
I have a simple question related to one-line programming. First an example: function test(a)
I have a simple question regarding the Minimax algorithm: for example for the tic-tac-toe
Me and my colleagues have a question regarding SQL Server 2008 query length and
I have a simple question regarding java generics. How do I construct a generic
I have this (simple) question regarding an array. I am trying to get the
I have a simple question regarding PHP Classes. Multiple times I have seen other
I have a very simple question regarding BSTs. I have seen multiple definitions of
I'm new to JavaScript, and have a simple (I presume) question regarding best practices

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.