I need help in formatting a sql query.
I have a table EMP in SQL Server as below.
| ID | FName | LName | Salary |
| 1 | ABC | PQR | 12 |
| 2 | DEF | STU | 23 |
Now, I want to fire a query in a way that I get the results in the following format -
ID - FName
1 - ABC
2 - DEF
-----------
I am not able to get that "-" sign. PLease Help.
Thanks in advance.

Ravi ShekharRank #673 · 3.6K reputationPosted Jun 15, 2013, 1:45 AM EDT
select convert(varchar(max), ID) + ' - ' + convert(varchar(max), FName) as 'ID-FName' from EMP
if this answer helped you .Please mark it as answer.
Regards,
Ravi
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Jun 17, 2013, 10:44 AM EDT
select convert(varchar(50), ID ) + '-' + FName as ID-FName from EMP
here we are concatenating string to int so conversion required.
if your Id field is Varchar then no need of conversion .
Any problem Rply
Jignesh TrivediRank #16 · 50.3K reputationPosted Jun 17, 2013, 7:01 PM EDT
agree with above two answer.
select convert(varchar(15), ID) + ' - ' + FName as [ID-FName] from EMP
let us know if you facing any other problem.
selva kumarRank #2,987 · 483 reputationPosted Jun 18, 2013, 12:00 AM EDT
select cast(ID as varchar(10)) + '-'+ FName as coumn1 from
Riddhi ValechaRank #794 · 2.9K reputationPosted Jun 23, 2013, 6:58 PM EDT
Thanks a lot for such a great help.......
I ended up using all the queries.... Hence... Thanks a ton once again to all..