Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...I am very impressed with the site and have already recommended it to one of my associates. I was truly impressed with the quickness in which someone actually responded to my question..."

Geography

Where in the world do Tek-Tips members come from?

Converting 'Long Date' to 'Short Date' and using the 'Short Date' in the 'Group By'Helpful Member! 

barnettjacob (IS/IT--Management)
14 Aug 12 21:20
Hi, I've got the following query which I'm trying to streamline to bring through summarized data. The problem is that in our database all the sales are recorded as a 'long' date with the time which means I am struggling to summarize by day. I've got the code to reformat the date which works well but I can't get that to drive the 'group by' which kind of defeats the object!

Any help would be appreciated.
Jacob

CODE --> SQL

select

p.Analysis1Code,
p.Supplier1,
s.branchCode,
(SELECT CONVERT(VARCHAR(10), Saledate, 103)) as date,
sum(quantity),
sum(fcextendednetamount-fcextendedtaxamount) as 'FCNetSales',
sum(grossprofitalternategp) as 'AltGP',

from eee..vwsaleline_gp s
join eee..product p on p.productcode = s.productcode

where saledate >= '07/01/10' 

group by (SELECT CONVERT(VARCHAR(10), Saledate, 103)), p.Analysis1Code, p.Supplier1, s.branchCode

order by s.BranchCode, s.saledate, p.Analysis1Code,p.Supplier1 
Helpful Member!  r937 (TechnicalUser)
14 Aug 12 23:03

CODE

SELECT s.branchCode
     , CONVERT(VARCHAR(10),Saledate,103) AS the_date
     , p.Analysis1Code
     , p.Supplier1
     , SUM(quantity)
     , SUM(fcextendednetamount-fcextendedtaxamount) AS 'FCNetSales'
     , SUM(grossprofitalternategp) AS 'AltGP'
  FROM eee..vwsaleline_gp AS s
INNER  
  JOIN eee..product AS p 
    ON p.productcode = s.productcode
 WHERE s.saledate >= '07/01/10' 
GROUP 
    BY s.BranchCode
     , the_date
     , p.Analysis1Code
     , p.Supplier1 
ORDER 
    BY s.BranchCode
     , the_date
     , p.Analysis1Code
     , p.Supplier1 

r937.com | rudy.ca
Buy my new book Simply SQL from Amazon

barnettjacob (IS/IT--Management)
14 Aug 12 23:30
Thanks Rudy, really appreciate it!
Jacob

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close