Hamed Zakery Miab
Hamed Zakery Miab

Reputation: 758

Enums in T-SQL, is it possible?

All of us know the system function DATEADD function (as an example). this function has 3 parameters which the first one is so strange for me. I looked on the Google so much for finding out the parameter type of the first parameter (which is shown varchar in Object Explorer window), but found nothing!

I think it's a kind of Enum used in this function because the usage is very similar to Enum usage:

Print DATEADD(DAY,1,GETDATE()) -- What's that DAY?

My question can be answered if one of this questions be replied:

  1. How can I see system functions definition?
  2. What's that DAY in above statement and how can I write a function like DATEADD to accept such parameter?
  3. If it's an enum, how can I define an enum in TSQL?

Upvotes: 4

Views: 737

Answers (1)

Siamak Ferdos
Siamak Ferdos

Reputation: 3299

Day is a type and its values can be:

yy, yyyy: year
qq, q: quarter
mm, m: month
dy, y: day of year
dd, d: day
wk, ww: week
dw, w: weekday
hh: hour
mi, n: minute
ss or s: second
ms: millisecond
mcs: microsecond
ns: nanosecond

Upvotes: 1

Related Questions