SQL Server Sum rows with string value -
I have a dynamic SQL query that gives lines as string values along the bottom; Numeric value
EMP call 1 call 2 coal 3 coal 4 coal 5 ---------------------------- 1 4 4 3 3 3 A2 4 2 5 3 3 A3 SD 3 3 1 SD A 4 3 4 3 3 3
Now I have a new column which is col5 to col5 plus total Where the amount column needs to be made it should ignore string values in line 3. There are no zero values
How can I get it? Using the ISGLEERIC
can be a solution, but I'm not sure how to use it in such a scenario.
You can use an expression to determine the value is a number. If it is a number then either put an value for an INT or decimal data type, otherwise 0 uses so the amount does not affect. Select
is the case when ISNUMERIC (col1) = 1 then cast (col1 as INT) and 0 end is the case when ISNUMERIC (col2) = 1 is then cast (INT) In col2) and 0 + is the case when ISNUMERIC (col3) = 1 is cast then (col3 as INT) and 0 end + case when ISLDERIC (col4) = 1 then cast (col4 as INT) and 0 end + Is the case when ISNUMERIC (col5) = 1 then cast (COL5 as INT) and 0 by MyTable
Comments
Post a Comment