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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:36:27+00:00 2026-06-15T16:36:27+00:00

Possible Duplicate: SQL Msg 8114, Level 16, State 5, Procedure sp_product_listing, Line 0 Error

  • 0

Possible Duplicate:
SQL Msg 8114, Level 16, State 5, Procedure sp_product_listing, Line 0 Error converting data type varchar to datetime

I’ve seen that this was asked a while ago by someone in another semester at my school, haha. But the answer they got didn’t really satisfy me. Here is the link to the other question: SQL Msg 8114, Level 16, State 5, Procedure sp_product_listing, Line 0 Error converting data type varchar to datetime.

Most of what the answer says makes not much sense to me as I am very new to SQL. If we could open up another discussion on this, it would be great. Especially minus the teacher bashing that has been going on in my questions lately…

The following statement completes successfully, BUT:

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

When I try and execute the procedure, I get an error message:

Msg 8114, Level 16, State 5, Procedure sp_product_listing, Line 0
Error converting data type varchar to datetime.

Here’s how I execute the stored procedure:

EXECUTE sp_product_listing @product = 'Jack%', @month = 'June', @year = 2001;
GO

I’ve tried changing the two datetime datatypes to varchars and that has not worked because the column itself is datetime datatype originally. I’m not sure what I’m missing here?

UPDATE:

This was the final solution as guided by https://stackoverflow.com/users/1554034/valex.

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

Also, for anyone still reading, here is the solution my teacher gave me which gives the same results.

CREATE PROCEDURE sp_product_listing
(
@product    varchar(30),
@month      varchar(10),
@year       char(4)
)
AS
    SELECT
       'product_name' = products.name,
       products.unit_price,
       products.quantity_in_stock,
       'supplier_name' = suppliers.name
    FROM
       suppliers
    INNER JOIN
       products ON suppliers.supplier_id = products.supplier_id
    INNER JOIN
       order_details ON products.product_id = order_details.product_id
    INNER JOIN
       orders ON order_details.order_id = orders.order_id
    WHERE   
       products.name LIKE @product 
       AND DATENAME(MONTH,orders.order_date) = @month 
       AND YEAR (orders.order_date) = @year;
   GO
  • 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-15T16:36:28+00:00Added an answer on June 15, 2026 at 4:36 pm

    You get this error because of ‘June’ is not a DATEIME value and MONTH function returns int. Also if you input @product as a MASK (with ‘%’) you should use LIKE instead of = So you should declare your procedure as:

    CREATE PROCEDURE    sp_product_listing
    (
    @product    varchar(30),
    @month      int,
    @year       int
    )
    
    ....
    WHERE               products.name LIKE @product AND
    ....
    

    And call it

    EXECUTE             sp_product_listing @product = 'Jack%', @month = 6, @year = 2001;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: SQL Server Text type vs. varchar data type Using varchar(MAX) vs TEXT
Possible Duplicate: Does SQL Server 2005 have an equivalent to MySql’s ENUM data type?
Possible Duplicate: LINQ to SQL: Return anonymous type? I have a standard LINQ to
Possible Duplicate: SQL left join vs multiple tables on FROM line? SELECT messages.message_title, messages.message_content,
Possible Duplicate: SQL Server UDF refresh The system stored procedure sp_refreshview can be used
Possible Duplicate: SQL Server Full text Index SQL Server stored procedure parameter output I
Possible Duplicate: SQL Server & .net support calling a stored procedure with param's values
Possible Duplicate: Sql Query throwing error I am trying a query for retrieving records
Possible Duplicate: SQL Query JOIN with Table If this is the data in TestingTable1
Possible Duplicate: sql query to sum the data I have following table structure TradeId

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.