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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:03:43+00:00 2026-06-12T22:03:43+00:00

I have a query in SQL Server 2008. SELECT CONVERT(char(80), i.InvDate,3) AS InvDate, i.InvoiceNo,

  • 0

I have a query in SQL Server 2008.

SELECT
    CONVERT(char(80), i.InvDate,3) AS InvDate,
    i.InvoiceNo,
    i.TaxAmount + i.SubTotal AS Amount,
    '' AS Payment,
    pd.GivenName
FROM
dbo.Invoice i
    INNER JOIN dbo.PatientDetails pd ON (pd.MedicalRecordID = i.MedicalRecordID)
    WHERE (InvDate >= CONVERT(datetime, '16/10/2012', 105)) AND 
(InvDate <= CONVERT(datetime, '16/10/2012', 105))

Output:

enter image description here

When i tried to put that into C#, it says “Conversion failed when converting date and/or time from character string.”


Info: 16/10/2012 are sample dates which i tried to insert into the query to make sure it runs. It’s a old program, thats why its converting from a string. I’m pretty sure its something gotta do with the datetime format. Had a look at http://www.sqlusa.com/bestpractices/datetimeconversion/. But i cant put a finger through it.

SqlCommand objCmd = new SqlCommand("SELECT CONVERT(char(80), i.InvDate,3) 

AS InvDate,

i.InvoiceNo, i.TaxAmount + i.SubTotal AS Amount,'' AS Payment,pd.GivenName 

FROM

dbo.Invoice i INNER JOIN dbo.PatientDetails pd

ON 
(pd.MedicalRecordID = i.MedicalRecordID)

WHERE

(InvDate >= CONVERT(datetime, 'dd/MM/yyyy', 105)) 

AND 

(InvDate <= CONVERT(datetime, 'dd/MM/yyyy', 105))", objConn);



        SqlDataReader objReader;
        objReader = objCmd.ExecuteReader();

        System.IO.FileStream fs = new System.IO.FileStream("C:\\CMSExportedData\\Sales-" + 
DateTime.Now.ToString("dd-MM-yyyy") + ".txt", System.IO.FileMode.Create);
        System.IO.StreamWriter sw = new System.IO.StreamWriter(fs,   
System.Text.Encoding.Default);
  • 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-12T22:03:45+00:00Added an answer on June 12, 2026 at 10:03 pm

    CONVERT(datetime, 'dd/MM/yyyy', 105) is attempting to convert the literal text dd/MM/yyyy into a datetime – that’s never going to work.

    SqlCommand objCmd = new SqlCommand(@"SELECT CONVERT(char(80), i.InvDate,3) 
    AS InvDate,
    i.InvoiceNo, i.TaxAmount + i.SubTotal AS Amount,'' AS Payment,pd.GivenName 
    FROM
    dbo.Invoice i INNER JOIN dbo.PatientDetails pd
    ON 
    (pd.MedicalRecordID = i.MedicalRecordID)
    WHERE
    (InvDate >= @StartDate) 
    AND 
    (InvDate <= @EndDate)", objConn);
    
    objCmd.Parameters.AddWithValue("@StartDate",/* some C# expression that gives you the start date, as a DateTime value */);
    objCmd.Parameters.AddWithValue("@EndDate",/* some C# expression that gives you the end date, as a DateTime value */);
    

    You’ll have to fill in the commented parts in the last two lines above. At a guess, from your previous question, they might be dtpFrom.Value and dtpTo.Value.

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

Sidebar

Related Questions

I have written a query in Sql server 2008. select select * from program
In sql server 2008, I have the following query: select c.title as categorytitle, s.title
I have query in SQL SERVER 2008 like this. And this is working. SELECT
I have a SQL Server 2008 query SELECT TOP 10 * FROM T WHERE
I have this problem with a SQL query (SQL Server 2008) SELECT id, client,
I have an SQL Query (For SQL Server 2008 R2) that takes a very
Using Microsoft SQL server 2008 I have a query that is in need of
I have created a T-SQL query in SQL Server 2008 R2 that is a
I have a nested query which when I execute in SQL server 2008 management
I have a Microsoft SQL Server 2008 query that returns data from three tables

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.