we heared something about typecasting in programming languages.at few times there may be situation to use converting string into integer or integer in to string in sql or Date in to strings
Now CAST or CONVERT are the two methods which can do the needfull
Example1:
So in the similar way we can use cast to convert any data types.
Example 2:
i have a column by name Registartiondate which is of datetime now i want to retrive only date part of the column but not time
Now CAST or CONVERT are the two methods which can do the needfull
Example1:
select (cast(empid as varchar(50))+'-'+e.empname) UID from employee
Result:
1234-Billgates
So in the similar way we can use cast to convert any data types.
Example 2:
i have a column by name Registartiondate which is of datetime now i want to retrive only date part of the column but not time
select convert (varchar,first_op_visit,101) Result1,convert (varchar,first_op_visit,100) Result2,convert (varchar,first_op_visit,102) Result3,convert (varchar,first_op_visit,106) Result4 from patient_profile
Result:
Result1 Result2 Result3 Result4
12/15/2004 Dec 15 2004 12:00AM 2004.12.15 15 Dec 2004
No comments:
Post a Comment