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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:56:09+00:00 2026-05-23T11:56:09+00:00

I have a sql server report which have startdate and enddate datetime parameters but

  • 0

I have a sql server report which have startdate and enddate datetime parameters but when i specify datetime in them the report show error

An error has occurred during report processing.
Exception has been thrown by the target of an invocation.
Conversion failed when converting date and/or time from character string.

startdate paramter have value 6/22/2011 12:00:00 AM when set as report parameter in C# code, My stored procedure code is

create PROCEDURE Price
@Startdate datetime = null,
@Enddate datetime = null    
AS    
declare @sql varchar(8000)
set @sql = 'SELECT CommodityPrice.dtm_Date FROM Commodity 
INNER JOIN CommodityPrice ON Commodity.int_CommodityId = CommodityPrice.int_CommodityId where Commodity.vcr_HSCode is not null ' 

IF (@Startdate <> '')
BEGIN   
        SET @sql = @sql + ' and CommodityPrice.dtm_Date >= '+ @Startdate

END
IF (@Enddate <> '')
BEGIN   
        SET @sql = @sql + ' and CommodityPrice.dtm_Date <= '+ @Enddate
END

set @sql = @sql+ ' order by CommodityPrice.dtm_Date desc'

exec (@sql)

How can i remove this issue? I am creating dynamic sql because i have some other paramters as well.

  • 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-23T11:56:10+00:00Added an answer on May 23, 2026 at 11:56 am

    My advice; don’t concatenate input ;p (as always). You can still use parameters with EXEC, especially with sp_ExecuteSQL. That will avoid all the issues and allow query-plan re-use.

    NEVER concatenate user input, even in TSQL. ALWAYS use parameters, unless it is absolutely impossible to do so.

    As a trivial example (in particular to show how the parameter names don’t need to match):

    declare @a int = 15, @b datetime = GETUTCDATE()
    
    declare @sql nvarchar(400) = 'select @x, @y'
    
    exec sp_executeSql @sql, N'@x int, @y datetime', @a, @b
    

    we are passing in @a and @b as parameters (mapping to @x and @y) to the SQL in @sql, and executing in a safe, re-usable, cachable way.

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

Sidebar

Related Questions

I have an SQL reporting server report which has 5 parameters which permit nullable
I have a report in SQL Server Reporting Services which should show a text
I have a SQL Server 2008 reporting services report which runs fine in preview
I have a SQL Server 2005 database which has about 30-40 connections to the
I have a SQL Server Reporting Services report with an embedded image in the
I have an SQL Server Reporting Services (SSRS) report, that uses a view. That
I have a report in SQL Server Reporting Services (SSRS) that I'd like to
I have a report in SQL 2005 reporting services. It is a server side
We have some SQL server reporting services reports. I didn't write then but I
I have a fairly basic SQL Server Reporting Services report that is using nested

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.