DYnamic SQL示例 [英] DYnamic SQL examples

查看:152
本文介绍了DYnamic SQL示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我学到了什么是动态的sql,而对我来说最有趣的一个特点就是我们可以使用动态列名和表。但我不能想到有用的现实生活中的例子。我唯一想到的就是统计表。让我们说我们有一个名字,类型和created_data的表。然后,我们想要一个表,其中列是几年从created_data列以及以类型创建的行类型和数量。 (对我的英文抱歉)



使用列和表作为参数的动态sql可以使用其他有用的实际生活示例吗?如何使用它?



感谢任何建议和帮助:)
认为
Gabe



/编辑
对于回复,我特别感兴趣的例子不包含管理事务或数据库转换或类似的东西,我正在寻找示例中的代码比例java更复杂一个动态的sql在例如存储过程。

解决方案

我曾经不得不编写一个Excel导入,其中excel表不像csv文件,但是像矩阵一样布局。所以我不得不处理3个临时表(列,行,内部)的未知数量的列。这些行也是一种简短的树形。听起来很奇怪,但是很有趣。
在SQL Server中,没有机会处理这个没有动态SQL。


I have lately learned what is dynamic sql and one of the most interesting features of it to me is that we can use dynamic columns names and tables. But I cannot think about useful real life examples. The only one that came into my mind is statistical table.

Let`s say that we have table with name, type and created_data. Then we want to have a table that in columns are years from created_data column and in row type and number of names created in years. (sorry for my English)

What can be other useful real life examples of using dynamic sql with column and table as parameters? How do you use it?

Thanks for any suggestions and help :) regards Gabe

/edit Thx for replies, I am particulary interested in examples that do not contain administrative things or database convertion or something like that, I am looking for examples where the code in example java is more complicated than using a dynamic sql in for example stored procedure.

解决方案

I once had to write an Excel import where the excel sheet was not like a csv file but layed out like a matrix. So I had to deal with a unknown number of columns for 3 temporary tables (columns, rows, "infield"). The rows were also a short form of tree. Sounds weird, but was a fun to do. In SQL Server there was no chance to handle this without dynamic SQL.

这篇关于DYnamic SQL示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆