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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:11:07+00:00 2026-05-25T06:11:07+00:00

For the [Submitted On] column, when @fiscalyear is selected, I want only data ending

  • 0

For the [Submitted On] column, when @fiscalyear is selected, I want only data ending that fiscal year.

For example if @fiscalyear = 2011 I want the data with [Submitted On] column ending with only the 2011 or null and likewise for the other years which is 2010 and 2012. Right now the problem is when i select 2012 0r 2010, I still get data with dates ending in 2011. Any ideas? And thanks to Aaron for the hint – my script looks different now.

@FiscalYear int,
@SchoolID int,
@Status int

AS
BEGIN

SET NOCOUNT ON;

declare @intCount int
declare @sqlstr nvarchar(2000)
set @intCount = 0

    Select @intCount = Count(*)

     From EnrollmentDateSchool Ed Right Outer Join 
    (select FP.FiscalYear, PrivateSchool.* from PrivateSchool
        INNER JOIN FiscalYearPrivateSchool FP ON PrivateSchool.PrivateSchoolID
     = FP.PrivateSchoolID) PS ON Ed.PrivateSchoolID = PS.PrivateSchoolID 
    Left Outer Join 
    Finance.dbo.Person P ON Ed.CreatedBy = P.PersonID
 WHERE FiscalYear=@FiscalYear AND PS.IsActive=1
 AND (@SchoolID = -1 OR SchoolID=@SchoolID)
 AND ( (@Status = -1) 
  OR (@Status=1 AND PS.PrivateSchoolID = Ed.PrivateSchoolID) 
  OR (Ed.PrivateSchoolID is null) )
  IF @intCount > 0
  BEGIN

  Select
    [SchoolName] As [School Name],
    Status = CASE WHEN PS.PrivateSchoolID = Ed.PrivateSchoolID
      THEN 'Submitted'
      ELSE 'Not Submitted'
    END,
    [Submitted By] = CASE WHEN PS.PrivateSchoolID = Ed.PrivateSchoolID
      THEN [FirstName] + ' ' + [LastName]
      ELSE NULL
    END,
    [Submitted On] = CASE WHEN PS.PrivateSchoolID = Ed.PrivateSchoolID
      THEN Convert( Varchar(10), Ed.CreatedDate, 101 )
      ELSE NULL
    END
  From EnrollmentDateSchool Ed Right Outer Join
       (select FP.FiscalYear, PrivateSchool.*
        from PrivateSchool INNER JOIN
             FiscalYearPrivateSchool FP ON
               PrivateSchool.PrivateSchoolID = FP.PrivateSchoolID) PS ON
          Ed.PrivateSchoolID = PS.PrivateSchoolID Left Outer Join
       Finance.dbo.Person P ON Ed.CreatedBy = P.PersonID
 END
 Else Select 'No Data Found' as 'School Roster Certification Report'
 END
  • 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-25T06:11:08+00:00Added an answer on May 25, 2026 at 6:11 am

    Selecting COUNT(*) and then comparing that result against 0 means that the server has to do all of the work to retrieve the entire result set, even if it immediately found a matching row. You could replace this with an EXISTS test directly in your if statement, e.g.:

    IF EXISTS (SELECT * FROM /* Current Query */)
    BEGIN
    
    END
    

    Alternatively, depending on how your consuming the results from this stored proc (I’d imagine it already has to do some clever stuff, given that the two possible result sets from results available or not available have different shapes) would be to just have your inner query (appropriately modified), and then add this below it:

    IF @@ROWCOUNT=0
    BEGIN
        Select 'No Data Found' as 'School Roster Certification Report'
    END
    

    @@ROWCOUNT:

    Returns the number of rows affected by the last statement.

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

Sidebar

Related Questions

I have a [DataContract] called ReportRequest with a NOT NULL column 'SubmittedAt'. So my
EDIT: I have submitted a bug report and Microsoft have acknowledge that it is
I've submitted an app to the store that has been localised into a number
I have a database of information that was submitted from a website. The main
I have this sp. I just found out that M.MDS_FILE column, contains a file
I building a simple search feature that checks against a column desc in mysql
In looking at similar questions like: Getting trigger to insert changed column values only
Here is the problem. I have a stored procedure that transforms normalized data into
I've just begun diving into data warehousing and I have one question that I
The Transact-Sql Count Distinct operation counts all non-null values in a column. I need

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.