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
 combining a field and non-field together

Author  Topic 

rkeith27
Starting Member

5 Posts

Posted - 2009-03-12 : 13:29:16
How can I take this query that returns 2 columns and get it to only return 1 column with some formating?
SELECT description_long, count(*) AS facilityCount FROM vwFacilities GROUP BY description_long


I'm am trying to get it to return:
description_long_is_here (count_is_here)


I've tried using & and + but nothing seems to work. I either get a field not valid or aggregate error.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-03-12 : 13:33:45
[code]SELECT description_long + ' (' CAST( count(*) AS varchar(15)) + ')' AS facilityCount FROM vwFacilities GROUP BY description_long[/code]

however you should try to do this formating at your front end application as sql is not meant for this
Go to Top of Page

rkeith27
Starting Member

5 Posts

Posted - 2009-03-12 : 13:36:49
Ahhh.... you have to CAST it.
Thanks. I was so close yet so far away.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-03-12 : 13:44:29
welcome...
please consider doing this at front end strongly
Go to Top of Page
   

- Advertisement -