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.
| Author |
Topic |
|
nmarks
Yak Posting Veteran
53 Posts |
Posted - 2007-10-02 : 06:18:23
|
| Hi,Is it possible to convert an nvarchar type to a field name type?For example if I have a nvarchar called 'Sex' set to 'Male' and want a SELECT statement get data from the [Male] column in a table how can I convert the 'Sex' nvarchar to a field name type?Is that possible?I know CONVERT and CAST exist but I'm not sure how to use them.Help very much appreciated. |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-10-02 : 06:24:56
|
SELECT SUM(CASE WHEN Sex = 'Male' THEN 1 ELSE 0 END) AS Male,SUM(CASE WHEN Sex = 'Female' THEN 1 ELSE 0 END) AS FemaleFROM Table1 E 12°55'05.25"N 56°04'39.16" |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2007-10-02 : 07:49:32
|
| "SELECT statement get data from the [Male] column in a table how can I convert the 'Sex' nvarchar to a field name type?"You have a column called [Sex]Do you also have a column called [Male]? In a different table?Or is "Male" just a value in the [Sex] column?Kristen |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-10-03 : 03:13:03
|
quote: Originally posted by nmarks Hi,Is it possible to convert an nvarchar type to a field name type?For example if I have a nvarchar called 'Sex' set to 'Male' and want a SELECT statement get data from the [Male] column in a table how can I convert the 'Sex' nvarchar to a field name type?Is that possible?I know CONVERT and CAST exist but I'm not sure how to use them.Help very much appreciated.
Question seems unclearPost table structure, sample data and expected resultMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|