Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Select and Group by SubString

Posted on 2010-11-30
2
Medium Priority
?
741 Views
Last Modified: 2012-05-10
My attached code produces output as follows below
BusType       DealID
LT                  8001
LT                  8001
LT                  8001
SS                 1600
SS                 1600
SS                 1600

How do I modify my original select statement so I get the output below?
I'd rather not use a temp table
BusType       DealID
LT                  8001
SS                 1600

Declare @OrdTranID int
Set @OrdTranID = 9001

Select	Left(afsSource,2) as busType,
		SubString(afsSource,4,4) as DealID	
from	proc_cfa.dbo.P_AvailableForSale
where	afsTransAction = @OrdTranID

Open in new window

0
Comment
Question by:lrbrister
2 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 34238431
this should do:
Declare @OrdTranID int
Set @OrdTranID = 9001

Select  Left(afsSource,2) as busType,
                SubString(afsSource,4,4) as DealID      
from    proc_cfa.dbo.P_AvailableForSale
where   afsTransAction = @OrdTranID
group by Left(afsSource,2), SubString(afsSource,4,4)

Open in new window

0
 

Author Closing Comment

by:lrbrister
ID: 34238442
Great,
Thanks...I had a typo in my efforts.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question