Structured Query Language (SQL) provides you with the tools to update, delete, select and edit your table's data. SQL is similar to other programming languages. SQL has internal functions that allow you to manipulate and calculate data and execute them on your SQL server. One such internal function is the "Convert" statement. The "Convert" function changes the data type for a variable such as the conversion from a date to a string.
Create SQL variables to hold your values. The first variable contains your date. After the date is converted, you need to assign it to a string variable. The following code shows you how to define variables in SQL:
declare @date datetime
declare @string varchar(30)
Assign a date value to your datetime variable. The following code assigns a date in SQL:
set @date = '5/7/2010'
Convert the date to a string and assign it to the string variable created in step one. The following code shows you how to convert a date to a string:
set @string = convert(varchar(30), @date)
The first parameter in the "convert" function is the "varchar(30)" value. "Varchar(30)" is a string in SQL. The "30" value indicates that the string can contain no more than 30 characters. The second parameter is the variable that is converted.
Press the "F5" key to execute the statement. You can also use the following code to print the results to your SQL console, which verifies the conversion's success"
- Photo Credit Calendar image by Sergey Yakovenko from Fotolia.com
How to Convert Microsoft SQL Date to String
Microsoft SQL Server is a database application that has the capacity to hold millions of records within its tables. Programmers use stored...
How to Convert Date Format in Transact-SQL
Converting date formats in Transact-SQL is a trivial task when using the supplied functions for datetime-to-character conversion. For nearly all standard date...
String Functions in Oracle SQL
String functions in an Oracle database system can perform many different tasks, and developers often make use of SQL string functions regardless...