Link to home
Create AccountLog in
Avatar of amillyard
amillyardFlag 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

Avatar of qasim_md
qasim_md
Flag of United States of America image

BCP queryout the query to a .CSV file.
Avatar of 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
Avatar of Ephraim Wangoya
Ephraim Wangoya
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account