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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Sybase List function with Sum with SQL server?

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 Batchnr

This 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 these

I 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 MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

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 MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs


Go to Top of Page

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 MVP
http://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 this


Select batchnr,SUM(quant) AS TotalQty
From tblBatch
group by batchnr


and if you want this to be merged to something else do like below


SELECT *
FROM tblBill bl
INNER JOIN (Select tr_id ,batchnr,SUM(quant) AS TotalQty
From tblBatch
group by tr_id ,batchnr )b
ON b.tr_id = bl.kfr_trans_id


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -