将正则表达式与 SQL Server BIDS 结合使用
我正在使用 SQL Server BIDS(商业智能开发工作室,VS2008)编写报告,并且需要从字段值中删除标点符号。
例如,如果字段值为“Hello, World!”,我希望报告将该值显示为“Hello World”。我知道在这个例子中使用嵌套的替换函数很容易:
=Replace(Replace(Fields!Description.Value,",",""),"!","")
但是如果我必须删除的不仅仅是“,”和“!”,这很快就会变得“丑陋”。人物。简而言之:
我可以使用正则表达式来格式化 SQL Server BIDS 报告中的字段值吗?
如果答案是“否”,那很好,这样我就不用浪费时间去寻找它了!谢谢。
更新
在表达式公式中使用正则表达式(尽管这是针对电话号码的):
=System.Text.RegularExpressions.Regex.Replace(Fields!Phone.Value, "(\d{3})[ -.]*(\d{3})[ -.]*(\d{4})", "($1) $2-$3")
I'm writing a report using SQL Server BIDS (Business Intelligence Development Studio, VS2008), and I have the requirement to remove punctuation from field values.
For example, if the field value is "Hello, World!", I want the report to show the value as "Hello World". I'm aware in this example it'd be easy enough to use the Replace function, nested:
=Replace(Replace(Fields!Description.Value,",",""),"!","")
But this quickly becomes 'ugly' if I have to remove more than just "," and "!" characters. So, in short:
Can I use Regular Expressions to format field values in a SQL Server BIDS report?
If the answer is "no", that's fine, it'll save me wasting time trying to find it! Thanks.
UPDATE
Usage of Regex in expression formula (though this one is for phone numbers):
=System.Text.RegularExpressions.Regex.Replace(Fields!Phone.Value, "(\d{3})[ -.]*(\d{3})[ -.]*(\d{4})", "($1) $2-$3")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在客户端处理大量行可能需要一些时间。所以我建议将正则表达式逻辑移到服务器端。
为此,您可以使用 CLR 函数。
在此处查找示例: http://www.simple-talk.com/sql/t-sql-programming/clr-assemble-regex-functions-for-sql-server-by-example/
更新
如果您想在客户端处理另一方面,让您看看在报告中使用表达式(包括正则表达式):
http://msdn.microsoft.com/en-我们/库/ms157328(v=SQL.100).aspx
To process large set of rows on client side may take some time. So i propose to move Regex logic on Server side.
You can use CLR function for this.
Look for examples here: http://www.simple-talk.com/sql/t-sql-programming/clr-assembly-regex-functions-for-sql-server-by-example/
Update
If you want to process on client side, let you look at using expressions (include regex) in reports:
http://msdn.microsoft.com/en-us/library/ms157328(v=SQL.100).aspx