Hiya CC'ers,
I'm currently working on SQL Server 2005 reporting services. So this means I want to present data to people in an interesting and easy readable way.
But I've got a little problem and already searched but I don't think I enter the write tags when I search so I hope you guys can help me.
My problem is that I have a database in which I got different tables and one of those tables is called Persons.
In the person table there is a row called sex(male/female) now it doesnt say male or female but 0 or 1.
Well when I want to pull this data out and present it I want it to say like 0 = male and 1 = female. but how can I change this outcoming integer to a string?
I Don't want to change the Database!
so in the database it still says 0 or 1.
I really hope someone can help me!
Thanks In Advance!
//SterAllures
[SQL] Manipulate outcoming data
Started by SterAllures, May 20 2009 11:53 PM
8 replies to this topic
#1
Posted 20 May 2009 - 11:53 PM
4d 65 6c 76 69 6e 0d 0a
"If happiness was the national currency, what kind of work would make you rich?"
"If happiness was the national currency, what kind of work would make you rich?"
|
|
|
#2
Posted 21 May 2009 - 03:31 AM
Use the Case keyword as part of your select query.
SELECT CASE sex
WHEN 0 THEN "MALE"
WHEN 1 THEN "FEMALE"
AS gender
FROM persons
#3
Posted 21 May 2009 - 03:34 AM
Thanks for your fast reply!
I'll try it later today and let you know if it worked!! but thanks for the effort already!
I'll try it later today and let you know if it worked!! but thanks for the effort already!
4d 65 6c 76 69 6e 0d 0a
"If happiness was the national currency, what kind of work would make you rich?"
"If happiness was the national currency, what kind of work would make you rich?"
#4
Posted 21 May 2009 - 08:45 AM
Well I've tried the following
It gave me the following error: Incorrect syntax near the keyword 'As'
They ment the As in the sentence "As Gender"
I've also tried to do 'Female' and even '0' but it didn't work at all.
Any solution? Great thing by the way the CASE statement =)
SELECT CASE s.sex
WHEN 0 THEN "Male"
WHEN 1 THEN "Female"
As Gender
FROM staff s
It gave me the following error: Incorrect syntax near the keyword 'As'
They ment the As in the sentence "As Gender"
I've also tried to do 'Female' and even '0' but it didn't work at all.
Any solution? Great thing by the way the CASE statement =)
4d 65 6c 76 69 6e 0d 0a
"If happiness was the national currency, what kind of work would make you rich?"
"If happiness was the national currency, what kind of work would make you rich?"
#6
Posted 21 May 2009 - 08:59 AM
Wow that was with outta doubt the fastest reply ever :P.
and I tried it and it gave an error but another one so that was a good thing, so after changing the " into ' it worked!!!
I now have the following!
Ow ya btw I forgot the table name was staff and not persons :P
and I tried it and it gave an error but another one so that was a good thing, so after changing the " into ' it worked!!!
I now have the following!
SELECT CASE s.sex
WHEN 0 THEN 'Male'
WHEN 1 THEN 'Female'
END
As "Gender"
FROM staff s
Ow ya btw I forgot the table name was staff and not persons :P
4d 65 6c 76 69 6e 0d 0a
"If happiness was the national currency, what kind of work would make you rich?"
"If happiness was the national currency, what kind of work would make you rich?"
#7
Posted 21 May 2009 - 09:03 AM
I have witnessed (and posted) much faster responses - mainly in the Games (previously Lounge) areas.
I just copied your code and made the change, hence not picking up on the error. You can't blame me. ;)
Glad it works.
I just copied your code and made the change, hence not picking up on the error. You can't blame me. ;)
Glad it works.
#8
Posted 21 May 2009 - 09:06 AM
I'm not blaming you I'm happy you helped me out with this problem so I can get on. well than I change my statement into. That is with outta doubt the most fastest reply I ever got on a thread of mine :P.
But really Thanks a lot Xav and WingedPanther for your fast help!
But really Thanks a lot Xav and WingedPanther for your fast help!
4d 65 6c 76 69 6e 0d 0a
"If happiness was the national currency, what kind of work would make you rich?"
"If happiness was the national currency, what kind of work would make you rich?"


Sign In
Create Account


Back to top









