Solved

Use SQL to return date as a string

Posted on 2011-02-20
5
351 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 19

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Strange msg in the SSMS pane 13 60
How can I use this function? 3 32
Database maintenance 36 101
Need help separating values from a column and creating a new record 6 45
Introduction This article will provide a solution for an error that might occur installing a new SQL 2005 64-bit cluster. This article will assume that you are fully prepared to complete the installation and describes the error as it occurred durin…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

756 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