Click here to Skip to main content
16,004,833 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
SQL
string getUserDetail = "Select Id,Email,Name,Country,Convert(varchar (20), RegisterDate, 106) RegisterDate,Convert(varchar (20), LastLogin, 106) LastLogin ,Description,ImageName FROM [User] where Id='" + Id + "'";



What is this
SQL
CONVERT(varchar(20),LastLogin,106)LastLogin

in SQL Statement?

[edit]
DON'T SHOUT. Using all capitals is considered shouting on the internet, and rude (using all lower case is considered childish). Use proper capitalisation if you want to be taken seriously.
Code block added - OriginalGriff
[/edit]
Posted
Updated 23-Jun-11 21:04pm
v2

Here[^] is the first google hit I got. I assume LastLogin is a date, and it's converting it in to a string. 106 specifies what format the date should take in the string.
 
Share this answer
 
May I please suggest you a good school?
SQL Server CONVERT() Function[^] at w3schools.com
 
Share this answer
 
Convert is a function used to convert one data type to another.

Take a look at this link, its well explained. Convert function[^]

In your case the convert function is used to get datatime in a specific format. for 106 format is dd mon yy.
 
Share this answer
 
It converts Lastlogin field's data to varchar(20) (means only 20 characters allowed) format and show its output as lastlogin(Second) Field

Thanks.
 
Share this answer
 
Comments
CPallini 24-Jun-11 3:09am    
That's wrong, at least according to documentation.
It converts "LastLogin" column (which I believe is a Date value) value of each row to varchar(20) and name the column in the output as "LastLogin" (alias). The last parameter denotes the format option. Go though this link for detailed list of formats.

Hope this helps!
 
Share this answer
 
v2
The description is here: SQL CONVERT[^]

It converts datatypes: specifically, the column LastLogin is converted to a 20 character varchar field, with style 106, which means the date is formatted as "dd mon yy", so 3rd July 2009 would be converted to a string "01 JUL 09"
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900