How to create a dll in dotnet

To get something you never had, you have to do something you never did-Bimal Patel

Monday, January 10, 2011

Typecasting and Different Date Formats in Sqlserver

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:
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