Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
Pirre0001
Starting Member
19 Posts |
Posted - 2014-03-02 : 12:08:30
|
I have a subquery that retunrns multiple lines. To solve it, I have used the List function. The separation of List function is comma. TblBill is in the main query with many other tables.(Select List(tblBatch.batchnr) From tblBatch where tblBatch.tr_id = tblBill.kfr_trans_id ) As BatchnrThis subquery returns: B12, B13, B14, B43 and so on...Now I want to use SUM from another field (quant) from table tblBatch in the subquery and then separate those with a line break instead of comma.Batch number may occur several times and I want to summarize theseI want the subquery return like this:---Batchnr--- 3 B12 4 B13 1 B14 1 B43 and so on..How do I solve it the best way with SQL Server? |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2014-03-02 : 12:48:38
|
List is not a t-sql function so I guess you may be on Oracle. This is MS SQL Server forum so solutions given here are mostly t-sql centric. Please try you luck at Oracle forums like www.orafaq.com or www.dbforums.com for Oracle related here------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
Pirre0001
Starting Member
19 Posts |
Posted - 2014-03-02 : 12:51:38
|
I edit my post exactly when you post. I will use this functionality in SQL server?quote: Originally posted by visakh16 List is not a t-sql function so I guess you may be on Oracle. This is MS SQL Server forum so solutions given here are mostly t-sql centric. Please try you luck at Oracle forums like www.orafaq.com or www.dbforums.com for Oracle related here------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs
|
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2014-03-03 : 04:16:51
|
quote: Originally posted by Pirre0001 I edit my post exactly when you post. I will use this functionality in SQL server?quote: Originally posted by visakh16 List is not a t-sql function so I guess you may be on Oracle. This is MS SQL Server forum so solutions given here are mostly t-sql centric. Please try you luck at Oracle forums like www.orafaq.com or www.dbforums.com for Oracle related here------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs
You cant as List is not there in SQL server.in sql server your requirement can be obtained using query like thisSelect batchnr,SUM(quant) AS TotalQtyFrom tblBatch group by batchnr and if you want this to be merged to something else do like belowSELECT *FROM tblBill blINNER JOIN (Select tr_id ,batchnr,SUM(quant) AS TotalQtyFrom tblBatch group by tr_id ,batchnr )bON b.tr_id = bl.kfr_trans_id ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
|
|
|