Having said that, I'd advise you not to save that into a column. Dates should be kept in date formats, not varchar , until you actually need to query it.
At the most, you could use a computed column
ALTER TABLE YourTable
ADD FormattedDate AS ( CONVERT(char(8), YourDateColumn, 112) )
3条答案
按热度按时间dhxwm5r41#
Don't use
FORMAT
it's slow, and should only be used if you have no choice.Just use
CONVERT
with style 112 .db<>fiddle
Having said that, I'd advise you not to save that into a column. Dates should be kept in date formats, not
varchar
, until you actually need to query it.At the most, you could use a computed column
7uzetpgm2#
You can use the format, but my recommend is to use the DimDate(Table Date) and where clause with date and use dateint in select
a9wyjsp73#
I used this code: