简体   繁体   English

联接到MSSQL 2000中的表值函数吗?

[英]Join to table-valued function in MSSQL 2000?

I have a table with a whole name. 我有一张全名的桌子。 I have a function that receives said name, parses it, and returns a table with first, middle, last, and suffix. 我有一个函数,该函数接收所说的名称,对其进行解析,然后返回带有第一个,中间,最后一个和后缀的表。 I have a bad (edit: was "hyper-conservative") DBA who won't upgrade the dev server to the same version as the production one so I can't just use APPLY and be done with it: 我有一个bad (编辑:是“超级保守”的)DBA,他不会将开发服务器升级到与生产服务器相同的版本,所以我不能只使用APPLY并完成它:

insert into blah (name, firstName, middleName, lastName, suffix)
select a.name, b.firstName, b.middleName, b.lastName, b.suffix
from employees a CROSS APPLY dbo.parseName(a.name) b

Please help, or I will be forced to write code like this: 请帮忙,否则我将被迫编写如下代码:

insert into blah (name, firstName, middleName, lastName, suffix)
select 
    name, dbo.getNamePart(name, 'f') as firstName, 
    dbo.getNamePart(name, 'm') as middleName, 
    dbo.getNamePart(name, 'l') as lastName, 
    dbo.getNamePart(name, 's') as suffix 
from employees r  

It sounds like "dev" and "live" use different versions? 听起来“ dev”和“ live”使用不同的版本? Not using the same product on your dev/production servers is a liability . 在您的开发/生产服务器上不使用同一产品是一种责任 A "conservative" DBA should want them to match... “保守的” DBA应该希望他们匹配...

I'm unclear - are you writing the function that "returns a table with first, middle, last, and suffix", or consuming it. 我不清楚-您是在编写 “返回具有第一个,中间,最后一个和后缀的表”或使用它的函数。 If you are consuming it, you should just be able to SELECT from the UDF, or JOIN to it, etc. IIRC, you just alias the UDF as you would a table: 如果正在使用它,则应该只能够从UDF中进行SELECT ,或者将其JOIN到该表中,依此类推。IIRC,您只需对UDF进行别名,就像创建一个表一样:

...
from dbo.myTableUdf(...) x
inner join SomeTable y on x.id = y.id

You would be able to join to the UDF if it wasn't processing data from the other table. 如果UDF不在处理其他表中的数据,则可以加入其中。 That is, you can write this: 也就是说,您可以这样编写:

select name, b.EXPANSION
  from employees a
  join dbo.parseName('John Smith') b
    on a.CODE = b.CODE

but only because myFunc isn't referencing any fields in tb1. 但这仅仅是因为myFunc没有引用tb1中的任何字段。 That's what APPLY was created for. 这就是APPLY的创建目的。

The way I see it, you have three options: 从我的角度来看,您有三种选择:

  1. Your insert statement with one function reference per field 您的插入语句,每个字段具有一个函数引用
  2. A cursor over the result set, so the function can be called one row at a time 将光标放在结果集上,因此可以一次调用该函数一行
  3. Find a way to get the dev environment in sync with production, up to and including getting a better DBA. 寻找一种方法来使开发环境与生产保持同步,直至获得更好的DBA。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM