Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 formats and queries

Author  Topic 

JMOE
Starting Member

4 Posts

Posted - 2011-03-16 : 15:19:00
Hello All.
having some issue with my statment and/or import.

using a statment to count the number of rows by type and then format the count of rows into a number.
Issue Im having is when i load my sql statment into excel and run my query, the count of row column comes down as a text, which i have to format into number to be able to pivot table the data. but when i refresh my query, the row count column reverts back to a text (general) format and lose the ability to use my pivot table.

is there a way to code my sql statment so the row count is allready cast as interger when i run my query in excel or is there a way in excel to keep the column format as number.

SELECT

A.AsofDate,
datename(weekday,DATEPART(weekday,AsofDate))as Weekday,
A.NAME as List,
cast(COUNT(NAME) as int)AS Listcount

FROM
[x].[dbo].[x] as A

Where
AsofDate>=DateAdd(day, DateDiff(day,0,getdate()),-30)

group by
A.AsofDate,A.NAME

order by
AsofDate asc

X002548
Not Just a Number

15586 Posts

Posted - 2011-03-16 : 15:28:30
Did you say

"Run my Query in Excel"?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2011-03-16 : 15:32:57
This is an Excel issue. You don't need to cast count to int since it already is an int. Try Count(*) * 1 and see if that fools Excel into doing the right thing.

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

JMOE
Starting Member

4 Posts

Posted - 2011-03-16 : 15:47:43
jimf

YOUR AWESOME :)

FIXED..

COUNT(NAME) * 1 AS Listcount

thanks so much


Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2011-03-16 : 16:01:24
execl is such a piece of garbage...wait...it's good for what it does...

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page
   

- Advertisement -