سؤال

I've got a SELECT that gets, among other things,

CONVERT(varchar(10), TIMESTAMP)

where TimeStamp is defined as

[TIMESTAMP] [binary](8) NULL

Some of the timestamps have bad data, meaning instead of something like 0x30332F31372F3131, which converts to "03/17/11", they have only the bottom four bytes, as in 0x0000000002F09ADD.

When I do the SELECT in an MSSMS query window those bad ones come out blank, which is fine, but when I retrieve them in my program using an SqlDataReader the Strings for the bad timestamps come out with garbage characters, as in " ðšÝ".

Any ideas as to what I can do about this?

هل كانت مفيدة؟

المحلول

Select case when ISDate(CONVERT(varchar(10), TIMESTAMP))=1 then CONVERT(varchar(10), TIMESTAMP) else null end 
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top