Click here to Skip to main content
15,884,425 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
Hello,
I have a table

slno Number Type
1    100    P
1    101    A
2    200    P
2    202    A


As per the requirement i need to display
Police : 100
Ambulance:101
Emergency Police : 200
Emergency Ambulance: 202

Any one can solve this query.
Please help me.

[edit]Code block added - OriginalGriff[/edit]
Posted
Updated 5-Jul-12 21:46pm
v2
Comments
Sergey Alexandrovich Kryukov 6-Jul-12 3:36am    
How about just reading SQL reference? Not your destiny?
No, seriously: what did you try and what's the problem?
--SA
rohit24c 6-Jul-12 7:17am    
case type when 'P' then 'Police:' when 'A' then 'Ambulance' else 'Others' but then results in Police:100 Ambulance:101 Police:200 Ambulance:201 but i want it like Police:100 Ambulance:101 Emergency Police:200 Emergency Ambulance:201 here in the table i need to filter it based on slno also that i am not able to do.
Sandeep Mewara 6-Jul-12 4:15am    
Any effort?
rohit24c 6-Jul-12 5:29am    
case type
when 'P' then 'Police:'
when 'A' then 'Ambulance'
else 'Others'
but then results in
Police:100
Ambulance:101
Police:200
Ambulance:201
but i want it like
Police:100
Ambulance:101
Emergency Police:200
Emergency Ambulance:201

here in the table i need to filter it based on slno also that i am not able to do.
Arunprasath Natarajan 6-Jul-12 9:57am    
You have to give 2 condition. Check my eg.

CASE Typer
WHEN Number = 100 THEN Police : (rs!Number)
WHEN Number = 101 THEN Ambulance : (rs!Number)
...
ELSE ...
END

something like that..
 
Share this answer
 
Dear Friend,

Try this...

Select case when slno=1 and Type='P' then 'Police : '+Number
when slno=1 and Type='A' then 'Ambulance : '+Number
when slno=2 and Type='P' then 'Emergency Police : '+Number
when slno=2 and Type='A' then 'Emergency Ambulance : '+Number else
'No Number Found' end from your_Table
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900