Select Top 5 CreationDate , cast(Creationdate as DateTime...

0

Please login or register to vote for this query.

(click on this box to dismiss)

The Workplace Meta

Q&A about the site for members of the workforce navigating the professional setting

Select Top 5 CreationDate
, cast(Creationdate as DateTime) as CreatDatedatetime
, DATEADD(month, -3, GETDATE()) as Date3MonthsAgo
, DATEADD(month, 2, GETDATE()) as Date2MonthsFuture
, DATEDIFF(month,CreationDate,GETDATE()) as PostAgeMonths
, cast(CreationDate as Date) as CreationDateAsDate
, cast(CreationDate as Time(0)) as CreationDateAsTime -- 0 aiz Time nomet decimāldaļa
, cast(CreationDate as Varchar) as CrDateAsVarch
, convert(varchar, CreationDate, 104) as LVDateFormat --kāpec "varchar" iekļaujam?
, convert(varchar,Getdate(),104) as TodaysDateLvFormat --kāpec "varchar" iekļaujam?
, Month(CreationDate) as CreatDateMonth  -- Google meta daudz sarežģītākus risinājumus
, Year(CreationDate) as CreatDateYear
, case
when year(CreationDate)>=2022 --kāpēc nestrādā ar lauku no iepriekšējās dabulas CreatDateYear
then 'creat this year' 
else 'created earlier'
end as OldOrThisYear
, case 
when year(CreationDate)=2022 then 'this year'  -- varēja īsāk uzrakstīt
when year(CreationDate)=2021 then 'last year'
else 'old'
end as ThisLastOrOld

from posts;

--WHERE CreationDate>=CAST('2021-06-01' AS DATE) - kāpēc MD šāda rindiņa?
--AND CreationDate<=CAST('2021-06-05' AS DATE) - kāpēc MD šāda rindiņa?

Enter Parameters

Options:
Switch to main site
loading Hold tight while we fetch your results