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 |
|
MariaM
Starting Member
17 Posts |
Posted - 2005-03-29 : 07:46:47
|
| Hi, I have a problem with a query that maybe you can help me with. I have a table that looks something like this:orgnr kod sweden norway denmark11111 111 0 23 1222222 222 12 0 0The result i want to get is:orgnr kod anst land11111 111 23 norway11111 111 12 denmark22222 222 12 swedenThe countries with 0 anst should not be included. Is this possible to do ? Thank you for your help.Mariam |
|
|
andy8979
Starting Member
36 Posts |
Posted - 2005-03-29 : 08:24:22
|
Yes you can filter the data that you get from your query by putting the criteria in the Where clause syntax --Select [column name] from [table name] where anst <> 0 Or if you are using aggregate functions then you will have to use the having clause |
 |
|
|
MariaM
Starting Member
17 Posts |
Posted - 2005-03-29 : 08:26:22
|
| But how do I get the column names in the result as I want ?Mariam |
 |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2005-03-29 : 09:09:19
|
| the first thing to do, of course, is to stop everything and re-design your database. Of course, I'm sure you will say you don't have time to do it right, so alternatively you can write lots of lots of long SQL statements and work-arounds to give the illusion that your DB is actually designed correctly. To "fake normalize" your particular table, you can create a view of that table like this:create view YourView asselect orgnr, kod, sweden as anst, 'Sweden' as Landfrom YourTablewhere sweden <> 0union allselect orgnr, kod, norway as anst, 'norway' as Landfrom YourTablewhere norway <> 0union allselect orgnr, kod, denmark as anst, 'denmark' as Landfrom YourTablewhere denmark <>0- Jeff |
 |
|
|
|
|
|
|
|