Sql server – passing unquoted constants to functions like DATEPART does

constantsfunctionsql-server-2005

i would like to create a function which accepts a constant like
the datepart function accepts yy/mm/dd/hh/

like:

select datepart(dd, getdate())

i would like to create my own function that accepts dd
not char like 'dd'

i want

select MyFunc(dd, getdate())

and not

select MyFunc('dd', getdate())

Best Solution

i would like to create my own function that accepts dd not char like 'dd'

I think you're out of luck on this. If you don't single-quote the characters, they'll be interpreted as a name--but you can't have defined them as a name anywhere if you want them to be used in the manner you propose.