![]() |
| |||||||
| Sponsored Links |
![]() |
| | LinkBack (1) | Thread Tools | Display Modes |
#1
| |||
| |||
| Hello everyone, peebman2000 semi-beginner programmer. I have a quick question for one of my sql queries i'm using for a .net app. Below is my query they returns the count in some columns as well as the percent. When you look at the select as percent is my percent field. I want to show a '%' after return percent value. Currently it returns as 7.9, but I want it to return as 7.9%. I tried just doing + '%' but that didn't work. Can anyone give me the solution on using this query and adding the '%' at the end of my return results. I appreciate any help, thanks. sql query: Code: Select *, round(cast((convert(float,implemented) * 100.00 /convert(float,total)) as float), 1) as 'percent' From( Select count(id) as total, sum(moreinfo) as More_info, sum(assigned) as Inprocess_team, sum(assigned_expert) as Inprocess_expert, sum(statewide) as Statewide, sum(outscope) as OutOfscope, sum(notimplemented) as NotImplmntd, sum(implemented) as Implemented, Agency from (Select id, case when step = 'GETTING MORE INFORMATION' then count(step) else 0 end as 'moreinfo', case when step = 'IN PROCESS-ASSIGNED TO A SUBJECT MATTER EXPERT' then count(step) else 0 end as 'assigned_expert', case when step = 'REFERRED TO STATEWIDE ISSUES TEAM' then count(step) else 0 end as 'statewide', case when step = 'NOT WITHIN THE SCOPE OF THIS PROGRAM' then count(step) else 0 end as 'outscope', case when step = 'NOT IMPLEMENTED' then count(step) else 0 end as 'notimplemented', case when step ='IMPLEMENTED' then count(step) else 0 end as 'implemented', case when step = 'IN PROCESS-ASSIGNED TO A TEAM' then count(step) else 0 end as 'assigned', agency from efficiency where time >= @DateFrom AND time < DATEADD(day, 1, @DateTo) group by id, step, agency) as new group by agency) as anothertable where agency = @agency order by agency |
| Sponsored Links |
|
#2
| ||||
| ||||
| try this: Code: convert(varchar(25),round(cast((convert(float,implemented) * 100.00 /convert(float,total)) as float), 1)) + '%' as 'percent'
__________________ Quote of the Month: Quality: The race for quality has no finish line- so technically, it's more like a death march. Questions to Ponder: What do you do when you see an endangered animal eating an endangered plant? iif([sarcasm]=true,iif([you have to ask]=true,"didn't work","ha ha ha"),"not sarcasm") copyright © 2008 sbenj69 |
|
#3
| ||||
| ||||
| I would say the best way to handle this is to format the string after the database outputs it to the application. If this is being returned to a GridView, for example, you can use the DataFormatString property to format the string into a percentage.
__________________ jmurrayhead If you agree with me... click the icon! If my post solved your problem, click the button in the lower right-hand corner of the post.If you like it here...throw us a few bones to help support us. Join our Folding team: DeveloperBarn Folding |
|
#4
| |||
| |||
| Hey thanks mehere that worked. Thanks for the help. |
|
#5
| |||
| |||
| Thanks for the reply jmurryhead, I have displayed in a gridview, but the results show as 7.90 and I tried changing the dataformatstring to {0.p1} I also tried {0.#%} and it still wouldn't give me 7.9% it would give me7.90%. Anyway I tried mehere way and that worked, so I guess i'll just do it that way. |
|
#6
| |||
| |||
| jmurrayhead, I tested the query in sql query editor and it showed the % sign like I want, but when I put it in the gridview it doesn't show the % sign. Which dataformatstring could I use to show % in the gridview? |
|
#8
| |||
| |||
| Thanks Jmurrayhead, that work but I didn't realize I didn't update the right datsource. So when I was testing it in the gridview I was using the wrong datasource. But your suggestion worked in the gridview as well as Meheres. I tried it in the gridview with and without the dataformatstring and it worked. Thanks for your help again. |
![]() |
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
LinkBacks (?)
LinkBack to this Thread: http://www.developerbarn.com/sql-development/80-sql-select-add-next-value.html | ||||
| Posted By | For | Type | Date | |
| DeveloperBarn Forums - ASP Help, ASP.Net Help, PHP Help, SQL Help, Tutorials, Windows Help | This thread | Refback | March 28th, 2008 09:24 AM | |