有一个复杂的SELECT查询,我想从中将所有行插入表变量,但是T-SQL不允许它.
同样,您不能将表变量与SELECT INTO或INSERT EXEC查询一起使用. http://odetocode.com/Articles/365.aspx
简短的例子:
declare @userData TABLE(
name varchar(30) NOT NULL,
oldlocation varchar(30) NOT NULL
)
SELECT name, location
INTO @userData
FROM myTable
INNER JOIN otherTable ON ...
WHERE age > 30
Run Code Online (Sandbox Code Playgroud)
表变量中的数据稍后将用于将其插入/更新回不同的表(大多数是具有次要更新的相同数据的副本).这样做的目的是简单地使脚本比SELECT INTO直接进入正确的表更易读,更容易定制.性能不是问题,因为rowcount它相当小,只在需要时手动运行.
......或者告诉我,如果我做错了.
试图从HQL查询创建一个对象,但只是无法弄清楚我做错了什么.
查询:
String query = "SELECT product.code, SUM(product.price), COUNT(product.code)
from Product AS product
GROUP BY product.code"
Run Code Online (Sandbox Code Playgroud)
(或者我应该使用新的MyCustomList(product.code,SUM(...,即使它没有映射?)现在我想将这个返回的列表转换为类似的对象:
class MyCustomList{
public String code;
public BigDecimal price;
public int total;
// Constructor
public MyCustomList(String code, String price, int total){ //...
Run Code Online (Sandbox Code Playgroud)
检索数据:
// This throws ClassCastException
List<MyCustomList> list = MyClass.find(query).fetch();
Run Code Online (Sandbox Code Playgroud)
使用Play框架
使用Microsoft SQL Server Management Studio 2008.我做了一个简单的事务:
BEGIN TRAN
SELECT ko.ID, os.ID AS ID2
FROM table_a AS ko
JOIN table_b AS os ON os.ID=ko.ID
WHERE (ko.the_date IS NOT NULL AND os.the_date IS NULL);
UPDATE table_b SET the_date=ko.the_date
FROM table_a AS ko
JOIN table_b AS os ON os.ID=ko.ID
WHERE (ko.the_date IS NOT NULL AND os.the_date IS NULL);
SELECT ko.ID, os.ID AS ID2
FROM table_a AS ko
JOIN table_b AS os ON os.ID=ko.ID
WHERE (ko.the_date IS NOT NULL AND os.the_date IS NULL);
ROLLBACK …Run Code Online (Sandbox Code Playgroud) 我有这样的映射:
@ManyToMany(cascade = CascadeType.PERSIST)
@JoinTable(
name="product_product_catalog",
joinColumns={@JoinColumn(name="product_catalog", referencedColumnName="product_catalog")},
inverseJoinColumns={@JoinColumn(name="product", referencedColumnName="product")})
public List<Product> products = new ArrayList<Product>();
Run Code Online (Sandbox Code Playgroud)
我可以很好地获取目录的产品,但我不能(动态)订购产品.我怎么能订购它们?我可能不得不用order-by子句写一个多对多的HQL查询?我虽然将orderBy字段名称字符串传递给查询,还是有更好的解决方案?
表是:products,product_catalog,product_product_catalog(associative table)
PS使用播放!我的实体的框架JPASupport.
我遇到了一个非常奇怪的IE8加载问题 - 每当我在页面上执行某些步骤时,IE8只会挂起并尝试永久加载webfonts(.eot文件).
重现步骤:
这是我得到的(页面不刷新,只是挂起或空白):

包含webfont的CSS:
@font-face {
font-family: 'WebSymbolsRegular';
src: url("typefaces/websymbols-regular-webfont.eot");
src: url("typefaces/websymbols-regular-webfont.eot?#iefix") format('embedded-opentype'), url("typefaces/websymbols-regular-webfont.woff") format('woff'), url("typefaces/websymbols-regular-webfont.ttf") format('truetype'), url("typefaces/websymbols-regular-webfont.svg#WebSymbolsRegular") format('svg');
font-weight: normal;
font-style: normal;
speak: none;
}
@font-face {
font-family: 'icomoon';
src: url("typefaces/icomoon.eot");
src: url("typefaces/icomoon.eot?#iefix") format('embedded-opentype'), url("typefaces/icomoon.woff") format('woff'), url("typefaces/icomoon.ttf") format('truetype'), url("typefaces/icomoon.svg#icomoon") format('svg');
font-weight: normal;
font-style: normal;
speak: none;
}
Run Code Online (Sandbox Code Playgroud)
我已经尝试禁用所有插件,gzip压缩等,但问题仍然存在.
该网站使用带有Mystile主题的Wordpress WooCommerce插件.
我在SharePoint 2007 DataFormWebPart上有一个基本的XSLT过滤器:
<xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row[((ddwrt:FormatDateTime(string(@MyDate) ,1061 ,'MM'))=$MyParameter)]"/>
Run Code Online (Sandbox Code Playgroud)
在$ MyParameter来自ASP.NET控件.但是尝试以任何其他方式设置变量值会导致错误:
<xsl:variable name="Rows">
<xsl:value-of select="/dsQueryResponse/Rows/Row[((ddwrt:FormatDateTime(string(@MyDate) ,1061 ,'MM'))=$MyParameter)]"/>
</xsl:variable>
Run Code Online (Sandbox Code Playgroud)
要么
<xsl:variable name="Rows">
/dsQueryResponse/Rows/Row[((ddwrt:FormatDateTime(string(@MyDate) ,1061 ,'MM'))=$MyParameter)]
</xsl:variable>
Run Code Online (Sandbox Code Playgroud)
我得到的错误是: 参数1必须返回一个节点集.- >计数($行)< -
最终,我试图实现类似的东西:
<xsl:variable name="Rows">
<xsl:choose>
<xsl:when test="($MyParameter2 = '1')">
<xsl:value-of select="/dsQueryResponse/Rows/Row[((ddwrt:FormatDateTime(string(@MyDate) ,1061 ,'MM'))=$MyParameter)]"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="/dsQueryResponse/Rows/Row[((ddwrt:FormatDateTime(string(@MyDate) ,1061 ,'MM'))=$otherParameter)]"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
Run Code Online (Sandbox Code Playgroud)
使用XSLT可以做到这一点,还是应该在SharePoint Designer中寻找其他可能性?
hql ×2
sql-server ×2
t-sql ×2
filter ×1
hibernate ×1
insert ×1
java ×1
jpa ×1
many-to-many ×1
object ×1
select ×1
sharepoint ×1
sql-order-by ×1
variables ×1
webfonts ×1
xslt ×1