Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Selecting issue in SQl Server

Selecting issue in SQl Server

Scheduled Pinned Locked Moved Database
csssharepointdatabasesql-serversysadmin
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rakeshs312
    wrote on last edited by
    #1

    I have a sp for selecting all the records(policies here) and it should display 3 records and remainig in 'all others' category and total. But this is displaying 'all others' if there is less than 3 records. Waht should do for this

    CREATE Procedure [dbo].[cpGetFirmRemittedPolicySummaryByPolicyType]
    @firmId int = null,
    @totalPoliciesToShow int = 0,
    @currentDate datetime = NULL
    AS
    BEGIN
    /******************************************************************************************

    Name: cpGetFirmRemittedPolicySummaryByPolicyType

    Description: Returns a dataset with the count of remitted policies types by
    MTD, YTD and Prior Year.

    Parmeters:
    @firmId - Id of the firm that need to retrieve data for

    @totalPoliciesToShow - The number of unique policy types to display for the current month. If there
    are more than totalPoliciesToShow policies in a given month the remaining ones are rolled up into
    the 'All Others' Category. If the value is 0, then there is no rollup into the 'All Others' category,
    all policy types are shown. There is one case where the 'All Others' category could still show with
    the @totalPoliciesToShow value of 0. That is when there are policy types that exist for YTD or Prior
    Year but not in MTD. In this case, the All others category will show zero for MTD but will have a
    value for YTD and/or Prior Year.

    @currentDate - Date to be used as current date. If the value is not supplied, then the current date
    is used. If a value is supplied, then that date is used to be considered as the current date. Added
    for testing purposes.

    Testing:
    -- Show all policies types for Firm Id 3244631 for the current date
    exec dbo.cpGetFirmRemittedPolicySummaryByPolicyType 4699056, 0

    -- Show top 3 policies types for Firm Id 3244631, rolling all others into ALL OTHERS for current date
    exec dbo.cpGetFirmRemittedPolicySummaryByPolicyType 3244631, 3

    -- Show top 3 policies types for Firm Id 3244631, rolling all others into ALL OTHERS, using 12/12/2012
    -- as current date
    exec dbo.cpGetFirmRemittedPolicySummaryByPolicyType 3244631, 3, '12/12/2012'

    ********************************************************************************************/

    SET NOCOUNT ON

    declare @debug bit = 0
    declare @ALL_OTHERS varchar(10) = 'All Others'

    -- If the @currentDate is NULL then use the current system date, otherwise use the date passed
    -- This is used for testing purpose

    L 1 Reply Last reply
    0
    • R rakeshs312

      I have a sp for selecting all the records(policies here) and it should display 3 records and remainig in 'all others' category and total. But this is displaying 'all others' if there is less than 3 records. Waht should do for this

      CREATE Procedure [dbo].[cpGetFirmRemittedPolicySummaryByPolicyType]
      @firmId int = null,
      @totalPoliciesToShow int = 0,
      @currentDate datetime = NULL
      AS
      BEGIN
      /******************************************************************************************

      Name: cpGetFirmRemittedPolicySummaryByPolicyType

      Description: Returns a dataset with the count of remitted policies types by
      MTD, YTD and Prior Year.

      Parmeters:
      @firmId - Id of the firm that need to retrieve data for

      @totalPoliciesToShow - The number of unique policy types to display for the current month. If there
      are more than totalPoliciesToShow policies in a given month the remaining ones are rolled up into
      the 'All Others' Category. If the value is 0, then there is no rollup into the 'All Others' category,
      all policy types are shown. There is one case where the 'All Others' category could still show with
      the @totalPoliciesToShow value of 0. That is when there are policy types that exist for YTD or Prior
      Year but not in MTD. In this case, the All others category will show zero for MTD but will have a
      value for YTD and/or Prior Year.

      @currentDate - Date to be used as current date. If the value is not supplied, then the current date
      is used. If a value is supplied, then that date is used to be considered as the current date. Added
      for testing purposes.

      Testing:
      -- Show all policies types for Firm Id 3244631 for the current date
      exec dbo.cpGetFirmRemittedPolicySummaryByPolicyType 4699056, 0

      -- Show top 3 policies types for Firm Id 3244631, rolling all others into ALL OTHERS for current date
      exec dbo.cpGetFirmRemittedPolicySummaryByPolicyType 3244631, 3

      -- Show top 3 policies types for Firm Id 3244631, rolling all others into ALL OTHERS, using 12/12/2012
      -- as current date
      exec dbo.cpGetFirmRemittedPolicySummaryByPolicyType 3244631, 3, '12/12/2012'

      ********************************************************************************************/

      SET NOCOUNT ON

      declare @debug bit = 0
      declare @ALL_OTHERS varchar(10) = 'All Others'

      -- If the @currentDate is NULL then use the current system date, otherwise use the date passed
      -- This is used for testing purpose

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      It might be helpfull if you divide this script into several simpeler stored procedures. Complex tasks are always easier when broken into smaller pieces.

      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] They hate us for our freedom![^]

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups