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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Need a little help with SQL

Author  Topic 

venkath
Posting Yak Master

202 Posts

Posted - 2008-06-03 : 12:48:46
Hi all

Need a little help with SQL.



Given the following data:


PO PRODUCT LTU
800 A 2
801 A 3
802 B 7
902 B 6


what I would like to do is to group the data by the 1st digit of the PO number & PRODUCT So for example the desire output is

PO PRODUCT LTU
8 A 5
8 B 7
9 B 6

Thanks


visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-06-03 : 12:57:27
[code]SELECT LEFT(CAST(PO AS varchar(5)),1) AS PO,
PRODUCT,
SUM(LTU) AS LTU
FROM Table
GROUP BY LEFT(CAST(PO AS varchar(5)),1),PRODUCT[/code]
Go to Top of Page
   

- Advertisement -