Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: SQL Server
Expertise: Beginner
Mar 24, 1997



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Dates in String Variables

I want to use a string variable with the date in it (format would be 02/22/96). How do I accomplish this?

You'll need to first convert the date to a string (the name of the function to do this varies with each product, so you'll have to check your documentation). Then, concatenate the rest of the string around the date, for example:

SELECT string||converted_date||rest_of_string 
     FROM TableA;
The double bars are the concatenation operator. Some languages also support a correlation name (alias) if you were selecting the concatenated string as I demonstrated above. For example, you might be able to use:
SELECT string||converted_date||rest_of_string AS stringa 
     FROM TableA;
In this example, the result set would be labeled "stringa" rather than the long "string||converted_date||rest_of_string" that might appear if you do not (or can not) use a correlation name.
DevX Pro
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date