Solved

Select and Group by SubString

Posted on 2010-11-30
2
728 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 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

895 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now