添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

Hello, I hope someone can help / tell me what I am doing wrong!

I have a table column which is formatted to Varchar(8) and contains date information in the format 21151103 (yyyymmdd).

I have been trying to use the following syntax in a SQl View to output this in the date format 03/11/2015.

CONVERT(Varchar(8), DateField, 103) AS DateValue

However, the output is delivered in the same format as the table i.e. 21151103

Many thanks in advance

Since 21151103 is the format SQL likes try:

declare @d varchar(8) = '21151103';
select CONVERT(VARCHAR(10),CAST(@d AS DATE),103);

Do not forget that you are adding two characters

Hi sz1,

Thank you for the suggestion, however I'm getting an error 'Cannot Call Methods on Date', which appears to be linked to a bug in SQL 2008 Error in view when using CONVERT(Date,GETDATE())

As it happens we are going to convert to SQL 2012 next month so unless someone comes up with an alternative option I'll have to be patient. :neutral_face:

HI sz1,

Same problem with Call Method on Date unfortunately.

Both options work as a query but as soon as you convert that to a view it throws a wobbly

But thank you for your time and effort. All good learning!