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 ShekharPosted Jun 15, 2013, 5:45 AM
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
Riddhi ValechaPosted Jun 23, 2013, 10:58 PM
Thanks a lot for such a great help.......
I ended up using all the queries.... Hence... Thanks a ton once again to all..
selva kumarPosted Jun 18, 2013, 4:00 AM
select cast(ID as varchar(10)) + '-'+ FName as coumn1 from
Jignesh TrivediPosted Jun 17, 2013, 11:01 PM
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.
Sanjeeb LenkaPosted Jun 17, 2013, 2:44 PM
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