Solved

Use SQL to return date as a string

Posted on 2011-02-20
5
349 Views
Last Modified: 2012-05-11
I need to return a datetime collumn value as a string.

The following is not correct.

string strRenewalDateSQL = "SELECT Convert(DateTime,DateAdd(month,1,LastPaidDate),101) AS RenewalDate ";
            strRenewalDateSQL += "FROM Subscriptions  WHERE UserID = '" + strUserID + "'";

What is the correct syntax?
0
Comment
Question by:Dovberman
  • 3
5 Comments
 
LVL 18

Expert Comment

by:Raheman M. Abdul
ID: 34939108
0
 

Author Comment

by:Dovberman
ID: 34939225
I tried :

string strRenewalDateSQL = "SELECT CONVERT(varchar,  LastPaidDate, 101) AS LastPaidDate ";
            strRenewalDateSQL += "FROM Subscriptions  WHERE UserID = '" + strUserID + "'";

This does not return LastPaidDate as a string.

Please help. I found it difficult to try several of the many examples.

Please correct the syntax.

Thanks,
0
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 250 total points
ID: 34939346
This last looks good to me.  What exactly is the problem/error message?
0
 

Author Comment

by:Dovberman
ID: 34939473
strUserID is not a valid user.

My code returned none as expected.

All is OK now.

Thanks,
0
 

Author Closing Comment

by:Dovberman
ID: 34939476
Thank you.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Recently, when I was asked to create a new SQL 2005 cluster, Microsoft released a new service pack for MS SQL 2005 what is Service Pack 3. When I finished the installation of MS SQL 2005 I found myself troubled why the installation of SP3 failed …
I am showing a way to read/import the excel data in table using SQL server 2005... Suppose there is an Excel file "Book1" at location "C:\temp" with column "First Name" and "Last Name". Now to import this Excel data into the table, we will use…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

806 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question