开发者

SQL Server: compare date to string with no leading zeros

it's the old DateTime conversion black hole:

tbl_a.dob (varchar) = "1/1/1980"
tbl_b.dob (datetime) = 01/01/1980 00:00:00

this does NOT work:

select * 
from tbl_a, tbl_b
where tbl_a.dob 开发者_JAVA技巧= convert(varchar, dob, 101)

because style 101 adds leasing zeroes to the datetime! "01/01/1980"


You should be able to go the opposite direction, converting the varchar to a datetime.

select *
    from tbl_a a
        inner join tbl_b b
            on cast(a.dob as datetime) = b.dob
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜