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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:47:31+00:00 2026-05-30T08:47:31+00:00

I have written a stored procedure, & to execute this procedure I need to

  • 0

I have written a stored procedure, & to execute this procedure I need to pass a IN parameter whose data-type is ‘DATE’.

Now I will tell about my IN parameter in short.

Suppose I want see the attendance of ‘December 2011’ , then I need to pass ‘IN’ parameter as “Previous_month_of_last_date” which is ‘2011-11-30’. Then my procedure executes and gives me whole December months attendance details.

Hope so you are still with me.

Now here comes my question.

I have provided user below GUI.User_Input

So user will select here ‘year’ & ‘month’, Suppose he want see ‘December 2011’ report, then he will select ‘2011’ as year and ‘December’ as month as Input.

Now I want to write a JavaScript code who will take both these ‘year’ and ‘month’ as input and will convert this year and month in “Previous_month’s_last_date ” format e.g ‘2011-11-30’ for ‘2011 December Report’.

So how should I need to write a script to pass correct input to my procedure.

Any suggestions will be helpful.

This is my stored procedure.

DELIMITER $$

USE `Sample`$$

DROP PROCEDURE IF EXISTS `Test`$$

CREATE DEFINER=`Sample`@`%` PROCEDURE `Test`(IN month_last_date DATE)
BEGIN
SELECT 
users.id AS Id,
users.first_name AS Employee,cl_territories.name AS Territory,
CASE MAX(CASE WHEN DATE_FORMAT(main.cdate,'%d')='01' THEN main.task
              WHEN DATE_FORMAT(DATE_ADD(month_last_date, INTERVAL 1 DAY),'%W')='SUNDAY' THEN 0
              WHEN main.cdate IS NULL THEN -1
         ELSE -2 END)
     WHEN -1 THEN 'NA'
     WHEN  0 THEN 'S'
     WHEN  1 THEN 'Y'
     WHEN  2 THEN 'C'
     WHEN  3 THEN 'S1'
     WHEN  4 THEN 'P'
     WHEN  5 THEN 'M'
     WHEN  6 THEN 'H'
     WHEN  7 THEN 'L'
END Day1,
CASE MAX(CASE WHEN DATE_FORMAT(main.cdate,'%d')='02' THEN main.task
              WHEN DATE_FORMAT(DATE_ADD(month_last_date, INTERVAL 2 DAY),'%W') ='SUNDAY' THEN 0
              WHEN main.cdate IS NULL THEN -1
         ELSE -2 END)
     WHEN -1 THEN 'NA'
     WHEN  0 THEN 'S'
      WHEN  1 THEN 'Y'
      WHEN  2 THEN 'C'
      WHEN  3 THEN 'S1'
      WHEN  4 THEN 'P'
      WHEN  5 THEN 'M'
      WHEN  6 THEN 'H'
      WHEN  7 THEN 'L'
END Day2,
.
.
. # upt o 31 days
CASE MAX(CASE WHEN DATE_FORMAT(main.cdate,'%d')='31' THEN main.task
              WHEN DATE_FORMAT(DATE_ADD(month_last_date, INTERVAL 31 DAY),'%W')='SUNDAY' THEN 0
              WHEN main.cdate IS NULL THEN -1
         ELSE -2 END)
     WHEN -1 THEN 'NA'
     WHEN  0 THEN 'S'
     WHEN  1 THEN 'Y'
     WHEN  2 THEN 'C'
     WHEN  3 THEN 'S1'
     WHEN  4 THEN 'P'
     WHEN  5 THEN 'M'
     WHEN  6 THEN 'H'
     WHEN  7 THEN 'L'
END Day31
FROM
users  LEFT JOIN users_cstm
ON users.id=users_cstm.id_c
LEFT JOIN cl_territories
ON users_cstm.cl_territories_id1_c=cl_territories.id
LEFT JOIN
(
SELECT DATE_FORMAT(cl_doctor_call.date_entered,'%Y-%m-%d')AS cdate,
  cl_doctor_call.created_by  AS emp,
  1     task     
  FROM 
  cl_doctor_call  
  WHERE 
  DATE_FORMAT(cl_doctor_call.date_entered,'%Y-%m-%d')>month_last_date AND
  DATE_FORMAT(cl_doctor_call.date_entered,'%Y-%m-%d')<=DATE_ADD(month_last_date, INTERVAL 30 DAY)

  UNION ALL
  SELECT 
  DATE_FORMAT(cl_chemist_call.date_entered,'%Y-%m-%d') AS  cdate,
  cl_chemist_call.created_by AS emp,
  2    task     
  FROM 
  cl_chemist_call
  WHERE 
  DATE_FORMAT(cl_chemist_call.date_entered,'%Y-%m-%d')>month_last_date AND
  DATE_FORMAT(cl_chemist_call.date_entered,'%Y-%m-%d')<=DATE_ADD(month_last_date, INTERVAL 30 DAY)

  UNION ALL
  SELECT 
  DATE_FORMAT(cl_stockist_call_cstm.calldate_c,'%Y-%m-%d') AS cdate,
  cl_stockist_call.created_by AS emp,
  3         task
  FROM 
  cl_stockist_call LEFT JOIN cl_stockist_call_cstm
  ON cl_stockist_call.id=cl_stockist_call_cstm.id_c
  WHERE 
  DATE_FORMAT(cl_stockist_call_cstm.calldate_c,'%Y-%m-%d')> month_last_date AND
  DATE_FORMAT(cl_stockist_call_cstm.calldate_c,'%Y-%m-%d')<=DATE_ADD(month_last_date, INTERVAL 30 DAY)

  UNION ALL
  SELECT DATE_FORMAT(cl_product_pramotional_call.date_entered,'%Y-%m-%d') AS cdate,
  cl_product_pramotional_call.created_by AS emp,
  4       task
  FROM cl_product_pramotional_call
  WHERE  
  DATE_FORMAT(cl_product_pramotional_call.date_entered,'%Y-%m-%d')>month_last_date AND
  DATE_FORMAT(cl_product_pramotional_call.date_entered,'%Y-%m-%d')<=DATE_ADD(month_last_date, INTERVAL 30 DAY)

  UNION ALL

  SELECT DATE_FORMAT(meetings.date_start,'%Y-%m-%d') AS cdate,
  meetings.created_by AS emp,
  5        task
  FROM meetings
  WHERE  
  DATE_FORMAT(meetings.date_start,'%Y-%m-%d')> month_last_date AND
  DATE_FORMAT(meetings.date_start,'%Y-%m-%d') <= DATE_ADD(month_last_date, INTERVAL 30 DAY)

  UNION ALL
SELECT DATE_FORMAT(cl_holidays_structures.holiday_date,'%Y-%m-%d') AS cdate,
users.id AS emp,
6    task
FROM users LEFT JOIN users_cstm
ON users.id=users_cstm.id_c
LEFT JOIN cl_states
ON users_cstm.cl_states_id1_c=cl_states.id
LEFT JOIN cl_holidays_structures
ON cl_holidays_structures.cl_states_id_c=users_cstm.cl_states_id1_c
WHERE  
DATE_FORMAT(cl_holidays_structures.holiday_date,'%Y-%m-%d')> month_last_date AND
DATE_FORMAT(cl_holidays_structures.holiday_date,'%Y-%m-%d') <= DATE_ADD(month_last_date, INTERVAL 30 DAY)
UNION ALL
SELECT cl_leave_management_cstm.from_date_c+ INTERVAL td.days DAY cdate, 
users.id AS emp,
7    task
FROM
  cl_leave_management LEFT JOIN cl_leave_management_cstm
  ON cl_leave_management.id=cl_leave_management_cstm.id_c
LEFT JOIN users 
  ON cl_leave_management.created_by = users.id
JOIN temp_days td
  ON DATEDIFF(cl_leave_management_cstm.to_date_c, cl_leave_management_cstm.from_date_c) >= td.days
WHERE DATE_FORMAT(cl_leave_management_cstm.from_date_c,'%Y-%m-%d')> month_last_date AND
 DATE_FORMAT(cl_leave_management_cstm.from_date_c,'%Y-%m-%d')<=DATE_ADD(month_last_date, INTERVAL 30 DAY) AND
 cl_leave_management_cstm.status_c='Approved'

 )AS main 
 ON main.emp = users.id 
 WHERE DATE_FORMAT(users.date_entered,'%Y-%m-%d')<= month_last_date
 GROUP BY users.id ;
 END$$

DELIMITER ;

And This is my SP’s Sample Output

Employee  Year       Month        1  2   3   4   5   6    7.... 
 John     2011      December      Y  Y   Y   H   Y   L    S....
 Jenny    2011      December      Y  Y   Y   Y   Y   M    S....
  .
  .
  .
all employees with all, these columns
  • 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-30T08:47:33+00:00Added an answer on May 30, 2026 at 8:47 am

    I’ve created a fiddle Here.

    HTML

    <form method="post" action="#" onsubmit="return false">
        <select id="year">
            <option value="2008">2008</option>
            <option value="2009">2009</option>
           <option value="2010">2010</option>
           <option value="2011">2011</option>
           <option value="2012">2012</option>
        </select>
    
        <select id="month">
            <option value="1">Jan</option>
            <option value="2">Feb</option>
            <option value="3">Mar</option>
            <option value="4">Apr</option>
            <option value="5">May</option>
            <option value="6">Jun</option>
            <option value="7">Jul</option>
            <option value="8">Aug</option>
            <option value="9">Sep</option>
            <option value="10">Oct</option>
            <option value="11">Nov</option>
            <option value="12">Dec</option>
    </select>
    
    <button id="filter" onclick="doFilter()">Filter</button>
    

    ​

    JAVASCRIPT

    function doFilter()
    {
        var theMonth = document.getElementById('month').value;
        var theYear = document.getElementById('year').value;  
        var d = new Date(theYear, (theMonth - 1), 0);
        var theDate=d.getFullYear()+" "+(d.getMonth()+1)+" "+d.getDate();
        alert(theDate);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hai Techies, I have some stored procedure which was written in SQL server.Now i
I have written below stored procedure. In which i need to create Two Temporary
I have written stored procedure to poll the data from the database in biztalk.but
I have written this stored procedure for one my operations in the database, but
I have written a stored procedure in SQL Server. Now its just that I
I have written a stored procedure that, yesterday, typically completed in under a second.
I have written a Stored procedure which return some fields from a temporary table
so I have written several stored procedures that act on individual rows of data
Scenario I have a stored procedure written in T-Sql using SQL Server 2005. SEL_ValuesByAssetName
I have a stored procedure which is written in c#: SqlConnection scn = new

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.