sql server - 将不加引号的常量传递给像DATEPART这样的函数 [英] sql server - passing unquoted constants to functions like DATEPART does
问题描述
我想创建一个接受像
这样的常量的函数,datepart函数接受 yy / mm / dd / hh /
$ b
like:
select datepart(dd,getdate())
select datepart(dd, getdate())
我想创建我自己的函数,它接受 dd
不像'dd'
i would like to create my own function that accepts dd
not char like 'dd'
我要
i want
选择MyFunc(dd,getdate())
select MyFunc(dd, getdate())
而不是
and not
选择MyFunc('dd',getdate())
select MyFunc('dd', getdate())
推荐答案
我想创建自己的函数,接受dd不是像'dd'这样的字符。
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.
这篇关于sql server - 将不加引号的常量传递给像DATEPART这样的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!