December 21, 2015 at 2:11 pm
I was trying to divide by 0, but then learned I have to Cast as Numeric.
not sure how that works, I've tried every syntax I can find online . . . .
select (
Cast((Select count(INFO_REQUEST_ID) as numeric (3)
from IRQ.TCM_INRQ))
/
Cast((Select count(Entry_Num) as numeric (5)
from [ADHOC].[ATS_ESH]
where Entry_Summary_Date > '1/1/2015')
December 21, 2015 at 2:17 pm
jeffshelix (12/21/2015)
I was trying to divide by 0, but then learned I have to Cast as Numeric.not sure how that works, I've tried every syntax I can find online . . . .
select (
Cast((Select count(INFO_REQUEST_ID) as numeric (3)
from IRQ.TCM_INRQ))
/
Cast((Select count(Entry_Num) as numeric (5)
from [ADHOC].[ATS_ESH]
where Entry_Summary_Date > '1/1/2015')
It is not at all clear to me what you are trying to here or what the issue is. The syntax you have here is not even close though because you have your cast mixed around a select statement. If you want to cast the count as a numeric it would be something like this.
select cast(count(Entry_Num) as numeric(5))
from [ADHOC].[ATS_ESH]
where Entry_Summary_Date > '20150101'
Notice I changed the date string a little bit. This is ANSI compliant and will work regardless of local settings for dateformat.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
December 21, 2015 at 2:21 pm
I was trying to divide by 0
Let me advise you against that. You'll get an error.
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
December 21, 2015 at 2:52 pm
The danger is real...
December 21, 2015 at 2:53 pm
I'm guessing that the actual issue is that he was inadvertently using integer division, since COUNT returns an integer.
Drew
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
December 21, 2015 at 3:47 pm
Jason A. Long (12/21/2015)
The danger is real...
Love the picture. That's priceless.
December 21, 2015 at 7:38 pm
Ed Wagner (12/21/2015)
Jason A. Long (12/21/2015)
The danger is real...Love the picture. That's priceless.
Home sweet home...gone!
😎
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply