插入所选行的列 [英] Insert columns from selected rows

查看:65
本文介绍了插入所选行的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

这里我的选择命令


来自itr的SELECT SUM(dbo.ITR.ITR_TransQty * dbo.ITR.ITR_UnitCostAmt)

其中itr_transdate介于''2007-12-01''和''2007-12-31''

group by itr_glacctnbr

have itr_glacctnbr =' '121101''


此语句只选择一个glaccount但我有超过15个glaccounts可供选择。


我可以使用此语句选择所有glaccount但我想选择特定的glaccounts


SELECT sUM(dbo.ITR.ITR_TransQty * dbo来自itr的.ITR.ITR_UnitCostAmt

其中itr_transdate介于''2007-12-01''和''2007-12-31''

group by itr_glacctnbr



我可以在行中获得结果,我想插入另一个名为''testgl'的表中。


该表包含字段所有不同的gl_accounts。 121101,121102,12103 ....等字段


如何转换列中的选定行并插入此表字段。


提前感谢你的回答。

Hi all,
here my select command

SELECT SUM(dbo.ITR.ITR_TransQty * dbo.ITR.ITR_UnitCostAmt) from itr
where itr_transdate between ''2007-12-01'' and ''2007-12-31''
group by itr_glacctnbr
having itr_glacctnbr=''121101''

This statement select only one glaccount but i have more than 15 glaccounts to select.

I can use this statement to select all glaccount but i want to select specific glaccounts

SELECT sUM(dbo.ITR.ITR_TransQty * dbo.ITR.ITR_UnitCostAmt) from itr
where itr_transdate between''2007-12-01'' and ''2007-12-31''
group by itr_glacctnbr


I can get result in rows that i want to inset into another table called ''testgl''

That table contains field of all different gl_accounts. fields like 121101, 121102,12103....etc


How to convert selected rows in column and insert on this table fields.

Thanks in advance for your answer.

推荐答案

我想我理解你的问题。

你想插入的不仅仅是第一个查询返回一行但不是第二个查询中的所有行???

如果是这样,如何在第一个查询中使用更多条件

ie HAVING itr_glacctnbr ='''121101''或itr_glacctnbr ='''121105''或.......


或者也许是另一个存储你要插入的itr_glacctnbr数字的表并将其加入第二个查询
I think I understand your question.
You want to insert more than the one row returned by the first query but not all the rows in the second ???

If so how about using more criteria in the first query
ie HAVING itr_glacctnbr=''121101'' or itr_glacctnbr=''121105'' or .......

Or maybe another table where you store the itr_glacctnbr numbers you want to insert and join it to the second query


感谢您的回复。

我尝试使用仍然没有得到结果。这里我的陈述


来自itr的SELECT SUM(dbo.ITR.ITR_TransQty * dbo.ITR.ITR_UnitCostAmt)

其中itr_transdate介于''2007-12-01 ''和''2007-12-31''

group by itr_glacctnbr

有itr_glacctnbr =''121101''or itr_glacctnbr =''121102''



此声明只给出121101的一个结果。不是121102.


如果我使用以下声明我可以得到121102的结果。


来自itr的SELECT SUM(dbo.ITR.ITR_TransQty * dbo.ITR.ITR_UnitCostAmt)

其中itr_transdate介于''2007-12-01''之间和''2007-12-31''

group by itr_glacctnbr

有itr_glacctnbr =''121102''


但是我想在一个声明中应该给出两个结果。因为我想在一个语句中过滤15个不同的itr_glaccounts。


我的表中有超过100个gl_accounts,但我只想要几个。
Thanks for your reply.
I have tried using having still i am not getting the result. here my statement

SELECT SUM(dbo.ITR.ITR_TransQty * dbo.ITR.ITR_UnitCostAmt) from itr
where itr_transdate between ''2007-12-01'' and ''2007-12-31''
group by itr_glacctnbr
having itr_glacctnbr=''121101''or itr_glacctnbr=''121102''


This statement give only one result for 121101. not for 121102.

If i use below statement i can get the result for 121102.

SELECT SUM(dbo.ITR.ITR_TransQty * dbo.ITR.ITR_UnitCostAmt) from itr
where itr_transdate between ''2007-12-01'' and ''2007-12-31''
group by itr_glacctnbr
having itr_glacctnbr=''121102''

But i want in one statement should give both result. because i want to filter 15 different itr_glaccounts in one statement.

I have more than 100 gl_accounts in my table but i want only few.



我想我理解你的问题。

你想插入多于第一个查询返回的一行而不是第二行中的所有行???


如果是这样如何在第一个查询中使用更多条件

即HAVING itr_glacctnbr =''121101''或itr_glacctnbr =''121105''或.......


或者也许是另一个表,你存储你要插入的itr_glacctnbr数字并将其加入第二个查询
I think I understand your question.
You want to insert more than the one row returned by the first query but not all the rows in the second ???

If so how about using more criteria in the first query
ie HAVING itr_glacctnbr=''121101'' or itr_glacctnbr=''121105'' or .......

Or maybe another table where you store the itr_glacctnbr numbers you want to insert and join it to the second query



谢谢delerna,


很抱歉上次回复。我的表没有该日期的任何数据。


现在我还有一个问题。


我在选择声明中得到这样的结果


45000

67786


分别为Itr_glacct 121101,121102的第一个结果。



这个结果我需要在另一个表中作为一行插入。


因为在另一个表中我有121101,121102等字段..


第一个选择命令行在此表上作为单行插入。


121101,121102

------------ ------------

45000,67786

Thanks delerna,

Sorry for last reply. My table doesn''t have any data with that date.

Now i have one more question.

I am getting the result like this for the select statement

45000
67786

First result for Itr_glacct 121101, 121102 respectively.


This result i need to insert in another table as one row.

Because in another table i have the fields like 121101, 121102..

First select command rows insert on the this table as single row.

121101, 121102
------------------------
45000, 67786


这篇关于插入所选行的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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