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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:32:50+00:00 2026-06-16T02:32:50+00:00

Trying to using parts of datetime as a variable in a procedure, so a

  • 0

Trying to using parts of datetime as a variable in a procedure, so a parameter would be a month like ‘June’. Here’s what I wrote

/* 3. Create a stored procedure called sp_product_listing listing a specified product ordered during a specified month and year. The product and the month and year will be input parameters for the stored procedure. Display the product name, unit price, and quantity in stock from the products table, and the supplier name from the suppliers table. Run the stored procedure displaying a product name containing Jack and the month of the order date is June and the year is 2001. The stored procedure should produce the result set listed below.*/

CREATE PROCEDURE sp_product_listing
(
    @product varchar(40),
    @month  datetime,
    @year datetime
)
AS
    SELECT
        'product_name'=products.name,
        'unit_price'=products.unit_price,
        'quantity_in_stock'=products.quantity_in_stock,
        'supplier_name'=suppliers.name
    FROM
        products
    INNER JOIN suppliers ON suppliers.supplier_id=products.supplier_id
    INNER JOIN order_details ON order_details.product_id=products.product_id
    INNER JOIN orders ON orders.order_id=order_details.order_id
    WHERE
        products.name LIKE '%@product%' AND MONTH(orders.order_date) = @month AND YEAR(orders.order_date) = @year;
GO

/*Execute procedure*/
EXECUTE sp_product_listing 'Jack','June','2001'

Procedure is tested working fine until I add the variables, then it goes to H trying to convert varchar to datetime?

I’ve tried things like @month MONTH(datetime), etc. Not sure how to approach this? Maybe that’s not even the problem?

  • 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-16T02:32:51+00:00Added an answer on June 16, 2026 at 2:32 am

    You should not make “@month” datetime because, as its nametype implies, it expects data on the form “date and time” like YYYY/MM/DD hh:mm:ss, and “June” does not fits on the pattern I just presented. If you want just make one column for dates, let’s call it [dateofsomething], then, you can pass a parameter “@date” (with type datetime) with a value like a normal date.

    Of course, if you want the current date, just use getdate()

    Good luck

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

Sidebar

Related Questions

I'm trying to get file contents, replace some parts of it using regular expressions
I'm trying using a TAdoTable component, On form Create I call .Append() and in
I'm trying to split up a string into two parts using regex. The string
I am trying to create a Custom control specifically for my application which would
i am trying to create a wpf app and have different parts in user
I am trying to create an XML file using TinyXML2. While there are many
With the new Action/Object parts of Open Graph, I'm trying to publish a DateTime
I'm trying create a simple background periodic task using Django-Celery-RabbitMQ combination. I installed Django
I am using SQL Server 2008 R2, I am trying to create a dataset
I'm trying to create a custom module using Magento's EAV structure and have been

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.