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 8026897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:38:09+00:00 2026-06-04T23:38:09+00:00

I created a query looking at some transaction information. The time period criteria is

  • 0

I created a query looking at some transaction information. The time period criteria is conditional – on the 5th of the month, it needs to look at days 16-last day of the previous month. On the 20th of the month, it needs to look at days 1-15 of the same month. It will run automatically. A fine gentleman or woman on Stack Overflow gave me the following stored procedure to use, which worked perfectly:

DECLARE @today SMALLDATETIME, @start SMALLDATETIME, @end SMALLDATETIME; 
SET @today = DATEADD(DAY, 0, DATEDIFF(DAY, 0, CURRENT_TIMESTAMP));

SET @start = DATEADD(DAY, 1-DAY(@today), @today); 
SET @end = DATEADD(DAY, 15, @start);  

IF DATEPART(DAY, @today) <= 15 
BEGIN     
    SET @start = DATEADD(MONTH, -1, @end);     
    SET @end = DATEADD(DAY, 1-DAY(@today), @today); 
END   

SELECT ... WHERE h.billed_date >= @start AND h.billed_date < @end; 

Now they want this converted to a view that they can access from a 3rd party data integration tool. Google tells me views can’t call stored procedures in SQL Server. Their DBA said the whole query could also be converted to a stored procedure. How do I convert a query into an SP so that it can be accessed by a data integration tool? Here’s a simplified version of the query.

SELECT
  c.customer_name
, cc.category_name
, h.acct_bal  

FROM 
customer c
inner join htransactions h on c.customer_id = h.customer_id
left outer join customer_category cc on cc.category_id = c.category_id

WHERE
h.billed date >= @start
AND h.billed date < @end

Thanks. I’m a business analyst trying to get better at SQL. My foundational querying SQL is getting stronger. I need to transistion to learning more about variables and stored procedures.

  • 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-06-04T23:38:11+00:00Added an answer on June 4, 2026 at 11:38 pm

    If this just needs to be a stored procedure, then:

    CREATE PROCEDURE dbo.PullData -- whatever
    AS
    BEGIN
        SET NOCOUNT ON;
    
        DECLARE @today SMALLDATETIME, @start SMALLDATETIME, @end SMALLDATETIME; 
    
        SET @today = DATEADD(DAY, 0, DATEDIFF(DAY, 0, CURRENT_TIMESTAMP));
    
        SET @start = DATEADD(DAY, 1-DAY(@today), @today); 
        SET @end = DATEADD(DAY, 15, @start);  
    
        IF DATEPART(DAY, @today) <= 15 
        BEGIN     
            SET @start = DATEADD(MONTH, -1, @end);     
            SET @end = DATEADD(DAY, 1-DAY(@today), @today); 
        END   
    
        SELECT ... WHERE h.billed_date >= @start AND h.billed_date < @end; 
    END
    GO
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am looking at some practice questions Assume that you've just created this table:
I have created a SQL query that runs on SQL Server 2008. For some
Alright, need some help created a query for an Oracle 10g DB. I have
I have created a .Net app which allows to query IIS logs of some
I'm looking for a simple query to say something about database performance We've created
I'm looking for help to create a query, to solve the following problem: Let's
I am looking to create a SQL query that collects the results from multiple
I am looking to create a 301 redirect based purely on a query string
I created a query that takes a database backup at certain specified location. I
I'm trying to create a created_at query range that will capture all records created

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.