Avatar of amillyard
amillyard
Flag for United Kingdom of Great Britain and Northern Ireland asked on

export sql results to excel

running the attached sql statement -- how do I get those results to simply create an MS Excel (with headers and the dataset results).
DECLARE @StartDateTime datetime
DECLARE @FinishDateTime datetime

SET @StartDateTime = '2011-02-01 00:00:00.000'
SET @FinishDateTime = '2011-02-28 23:59:59.999'

SELECT 

T1.[MSISDN] AS 'MSISDN'

,(SELECT COUNT(CAST(CDR_ID as bigint)) 
			FROM [MyDB].[dbo].[CDRData] 
			WHERE (Direction = 1) AND ([MSISDN] = T1.[MSISDN])
			  AND (CallClass = 1) AND (ChargeableDuration > 0)
			  AND (SetupTime BETWEEN @StartDateTime AND @FinishDateTime)) AS 'MO Calls'

FROM [MyDB].[dbo].[CDRData] T1

GROUP BY T1.[MSISDN]

Open in new window

Microsoft SQL Server 2008

Avatar of undefined
Last Comment
Ephraim Wangoya

8/22/2022 - Mon
qasim_md

BCP queryout the query to a .CSV file.
amillyard

ASKER
thanks qasim - do you have an example pertaining to the attached code to work through / understand? -- csv is ok -- but would really like to a achieve and MS Excel output where possible.  (csv out putting is still useful to know though)
ASKER CERTIFIED SOLUTION
Ephraim Wangoya

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck