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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:13:44+00:00 2026-05-13T20:13:44+00:00

I am trying to create a Stored Procedure that will be used for a

  • 0

I am trying to create a Stored Procedure that will be used for a Report and I want the 2 date parameters to have a DEFAULT value of today’s date and 1 month prior.

Is the below the proper way to do this? I was reading elsewhere that I should use COALESCE…(SEE HERE)This is a touchy production system so I wanted to double check before I went forward.

CREATE PROCEDURE spCaseNoteReport 
-- Add the parameters for the stored procedure here
@ContactStartDate DateTime = null,
@ContactEndDate DateTime = null
AS
IF @ContactStartDate is null
SET @ContactStartDate = dateadd(m,-1, CONVERT(date, GETDATE()))
IF @ContactEndDate is null
SET @ContactEndDate = CONVERT(date, GETDATE())
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT (id.LastName + ', ' + id.FirstName) AS 'MemberName'
      ,c.ContactDate
      ,Li.ItemDescription AS 'Location'
      ,c.PresentAtContact
      ,c.ContactDetails   
      ,c.InsertUser
      ,c.TimeSpentUnits

FROM dbo.tblCaseNotes c
    inner join dbo.tblIdentificationMap id
        on c.PersonID = id.PersonID
    left outer join dbo.tblCaseNoteContactLocation L
        on c.Casenoteid = L.Casenoteid
            inner join dbo.tblCaseNotesMaintItem Li
                on L.ContactLocationID = Li.ItemID

WHERE c.ContactDate BETWEEN @ContactStartDate AND @ContactEndDate

ORDER BY MemberName, c.ContactDate, c.InsertUser

END


continued

So when I actually tried to run the CREATE PROCEDURE for this I get the following errors –>

Msg 243, Level 16, State 1, Procedure spCaseNoteReport, Line 12
Type date is not a defined system type.
Msg 243, Level 16, State 1, Procedure spCaseNoteReport, Line 14
Type date is not a defined system type.

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

    Nothing wrong with this approach. I use it myself.

    Parameter defaults can only be constants or udfs so the alternative is to use udfs which honestly doesn’t really help.

    Edit: best way to remove a time component from datetime

    DATEADD(day, DATEDIFF(day, 0, GETDATE()), 0)
    

    See this excellent SO Q+A “Most efficient way in SQL Server to get date from date+time?” (not mine!)

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

Sidebar

Related Questions

I am using SQL Server 2005. I want to create a stored procedure that
I'm trying to convert the permanent tables used in a stored procedure to global
I have a stored procedure called sp_BulkInsert that inserts one .csv file into my
I am trying create a WCF service that leverages the WPF MediaPlayer on the
Trying to create my first iPhone app that would play back audio. When I
Trying to create a small monitor application that displays current internet usage as percentage
I'm trying to create a webapplication where I want to be able to plug-in
I'm trying to write a PowerShell script that will do the following: Executes a
Thanks everyone for the feedback Hi All, I'm am trying to create a stored
Trying to create a QtRuby application, I get the following error: /usr/lib64/ruby/site_ruby/1.8/Qt/qtruby4.rb:2144: [BUG] Segmentation

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.