I have the following Query:
create table #Result (Reward varchar(40), Value MONEY);
insert #Result exec GetCurrentCycleQualifierStatusByAccountId @AccountId=76011;
with cteFirstResults as
(select Reward, round(Value,2) as Value from #Result where Reward like '%Balance%'),
cteSecondResults as
(select Reward, convert(INTEGER, Value) as Value from #Result where Reward NOT like '%Balance%')
select * from cteFirstResults
UNION ALL
select * from cteSecondResults;
drop table #Result;
When running a select * individually against each "cte" table, I get the results I want.
But when run all together, I get something like:
Reward Value
------ -----
Daily Balance 4709.00
Value A 1.00
Value B 9.00
I want the Value A/Value B data to show without any decimal values as they do when running a select against the table directly. How do I combine the two queries into one to show this data correctly?
Round(value,0) does nothing.
I can not change the sproc from which I'm gathering the data, but I can make the temp table any way I like.
Thanks,
Jason
The solution:
create table #Result (Reward varchar(40), Value MONEY);
insert #Result exec GetCurrentCycleQualifierStatusByAccountId @AccountId=76011;
With cteFirstResults as
(
Select Reward, Value
From #Result
Where Reward like '%Balance%'
)
, cteSecondResults as
(
Select Reward, cast(Value as int) as Value
From #Result
Where Reward Not like '%Balance%'
)
Select Reward, Cast( Value As varchar(max)) As Value
From cteFirstResults
Union All
Select Reward, Cast( value As varchar(max)) as Value
From cteSecondResults;
drop table #Result;