|
INTERVIEW QUESTIONS
DATABASE
SQL SERVER
DETAILS
Question: What is the code to create a table having a column named DATE, which takes date in the format dd/mm/yyyy, in SQL Server2000? Or any format of date.
Answer: SELECTÂ CONVERT(varchar, GETDATE(), 103)
In this example the GETDATE() will return your sql server system date.
and the CONVERT is used to convert the date into the desired fomat.
Basically the CONVERT requires three arguments
1. Datatype
2. Date to Convert
3. Format style
Here is the list of style .....
Style ID Style Type 0 or 100 mon dd yyyy hh:miAM (or PM) 101 mm/dd/yy 102 yy.mm.dd 103 dd/mm/yy 104 dd.mm.yy 105 dd-mm-yy 106 dd mon yy 107 Mon dd, yy 108 hh:mm:ss 9 or 109 mon dd yyyy hh:mi:ss:mmmAM (or PM) 110 mm-dd-yy 111 yy/mm/dd 112 yymmdd 13 or 113 dd mon yyyy hh:mm:ss:mmm(24h) 114 hh:mi:ss:mmm(24h) 20 or 120 yyyy-mm-dd hh:mi:ss(24h) 21 or 121 yyyy-mm-dd hh:mi:ss.mmm(24h) 126 yyyy-mm-dd Thh:mm:ss.mmm(no spaces) 130 dd mon yyyy hh:mi:ss:mmmAM 131 dd/mm/yy hh:mi:ss:mmmAM
Enjoy the Code...
|
|
|
Category |
SQL Server Interview Questions & Answers -
Exam Mode /
Learning Mode
|
Rating |
(0.3) By 7341 users |
Added on |
7/25/2011 |
Views |
71044 |
Rate it! |
|
|
Question:
What is the code to create a table having a column named DATE, which takes date in the format dd/mm/yyyy, in SQL Server2000? Or any format of date.
Answer:
SELECTÂ CONVERT(varchar, GETDATE(), 103)
In this example the GETDATE() will return your sql server system date.
and the CONVERT is used to convert the date into the desired fomat.
Basically the CONVERT requires three arguments
1. Datatype
2. Date to Convert
3. Format style
Here is the list of style .....
Style ID Style Type 0 or 100 mon dd yyyy hh:miAM (or PM) 101 mm/dd/yy 102 yy.mm.dd 103 dd/mm/yy 104 dd.mm.yy 105 dd-mm-yy 106 dd mon yy 107 Mon dd, yy 108 hh:mm:ss 9 or 109 mon dd yyyy hh:mi:ss:mmmAM (or PM) 110 mm-dd-yy 111 yy/mm/dd 112 yymmdd 13 or 113 dd mon yyyy hh:mm:ss:mmm(24h) 114 hh:mi:ss:mmm(24h) 20 or 120 yyyy-mm-dd hh:mi:ss(24h) 21 or 121 yyyy-mm-dd hh:mi:ss.mmm(24h) 126 yyyy-mm-dd Thh:mm:ss.mmm(no spaces) 130 dd mon yyyy hh:mi:ss:mmmAM 131 dd/mm/yy hh:mi:ss:mmmAM
Enjoy the Code...
Source: CoolInterview.com
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|
|
Related Questions |
View Answer |
|
Can we generate a trigger for two tables? if so what is the query to generate a trigger for two tables employye table and department table with employee having department no.
|
View Answer
|
|
Write sql query for retrieving employee names from employee table who are having salary greater than 5000 without using where clause
|
View Answer
|
Please Note: We keep on updating better answers to this site. In case you are looking for Jobs, Pls Click Here Vyoms.com - Best Freshers & Experienced Jobs Website.
View All SQL Server Interview Questions & Answers - Exam Mode /
Learning Mode
|