开发者

SQL: Date format and Case Statement Question

I have some dates in the following format : YYYY-MM-DD HH:MM:SS

I would like it to be in this format: YYYY-MM-DD

Also, I am selecting another field with true and false values w开发者_如何学运维hich I would like to convert to 0's and 1's

Is this possible?

I am doing this in a dts package and noticed one more thing:

The last field I am selecting is a guid which is enclosed in {brackets} is there a way to take the brackets out


Well, if you are using SQL Server 2008, then there is a DATATYPE DATE, without time. You could CAST your date column to this format or convert it to VARCHAR(10) using the 120 format. So, if you are writing a query, you can use the following statement for your columns:

SELECT  CONVERT(DATE,DateColumn), /* Or CONVERT(VARCHAR(10),DateColumn,120) depending on what you want*/
        CASE BooleanColumn WHEN 'False' THEN 0 WHEN 'True' THEN 1 ELSE NULL END,
        REPLACE(REPLACE(GuidColumn,'{',''),'}','')
FROM myTable


The date format that you see is defined by application you use. So with out that information is hard to answer. With the boolean is the same situation.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜