| Author |
Topic |
|
TWD38
Starting Member
7 Posts |
Posted - 2012-02-24 : 10:20:02
|
| Hi guys,I have a select query that retrieves employers based on their zip code. I want to include the county name for each sub-query section. County name is not a field in my database though.Is there a way to define the field and assign it a value? I tried this:ELECT a.AGTY_ID_NM, COUNTY_NAME as "SEVIER", a.AGTY_SYS_CD FROM DSNP.PR01_T_EMPR aBut I get an error. Surely, there is a way to do this. |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-02-24 : 10:26:01
|
| if county name is not in table where will you get it from? i think you need to add it as a field in table and populate it------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
TWD38
Starting Member
7 Posts |
Posted - 2012-02-24 : 10:31:42
|
| I just want to include it in my query output. I would manually define the county name in the SELECT.Sample output:AGTY_ID_NM COUNTY NAME AGTY_ID_NMCITY OF QUITMAN WOOD COUNTY 2345CITY OF MINEOLA WOOD COUNTY 2313 |
 |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2012-02-24 : 10:40:02
|
Not 100% sure I get it, but maybe you have the alias backwards?:SELECT a.AGTY_ID_NM,'SEVIER' AS COUNTY_NAME,a.AGTY_SYS_CDFROM DSNP.PR01_T_EMPR a |
 |
|
|
TWD38
Starting Member
7 Posts |
Posted - 2012-02-24 : 10:43:32
|
| I think I'm getting this confused with case statements where I can define a specific value for a field, but the field has to exist in the table. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-02-24 : 10:46:55
|
quote: Originally posted by TWD38 I just want to include it in my query output. I would manually define the county name in the SELECT.Sample output:AGTY_ID_NM COUNTY NAME AGTY_ID_NMCITY OF QUITMAN WOOD COUNTY 2345CITY OF MINEOLA WOOD COUNTY 2313
thats not a recommended approach as its not scalable and maintainable. If you want it to be in result why not add it as a field in table?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
TWD38
Starting Member
7 Posts |
Posted - 2012-02-24 : 11:04:57
|
| I don't have permissions to alter or add to the tables. I can export my results to Access and create it there though. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-02-25 : 13:01:59
|
quote: Originally posted by TWD38 I don't have permissions to alter or add to the tables. I can export my results to Access and create it there though.
then you've keep on changing your case statement everytime a new county information have to be entered------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|