473,394 Members | 2,031 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Adding a column in query

5
I am working on Microsoft SQL Server Reporting Services(SSRS) and need to create dataset that shows 2 columns, one with values from the table StateCode in the database and the other column should show the meaning of each value in the StateCode table.

The StateCode table includes 3 values, 0,1,2 where:
  • 0 = Open
  • 1 = Won
  • 2 = Lost

My problem here is, that no column showing the meaning of StateCode values exists for those 3 values(Open,Won,Lost). Therefore I need to add that to my query, that is f.exs., when StateCode '0' is returned, 'Open' appears also in that row.

Is there any way to do that in the query?
Jan 16 '08 #1
2 1629
ck9663
2,878 Expert 2GB
I am working on Microsoft SQL Server Reporting Services(SSRS) and need to create dataset that shows 2 columns, one with values from the table StateCode in the database and the other column should show the meaning of each value in the StateCode table.

The StateCode table includes 3 values, 0,1,2 where:
  • 0 = Open
  • 1 = Won
  • 2 = Lost

My problem here is, that no column showing the meaning of StateCode values exists for those 3 values(Open,Won,Lost). Therefore I need to add that to my query, that is f.exs., when StateCode '0' is returned, 'Open' appears also in that row.

Is there any way to do that in the query?

if your list becomes longer and becomes more dynamic i would recommend you use a table...if this is that short list and more of static thing...

try:

Expand|Select|Wrap|Line Numbers
  1. SELECT field1, field2, andmoreotherfields, ...
  2. StateCodeDesc = 
  3. case when StateCode = '0' then 'Open'
  4. case when StateCode = '1' then 'Won'
  5. case when StateCode = '2' then 'Lost'
  6. else 'Undefined'
  7. end
  8. from yourTable ....
  9.  

-- CK
Jan 16 '08 #2
Gosi75
5
if your list becomes longer and becomes more dynamic i would recommend you use a table...if this is that short list and more of static thing...

try:

Expand|Select|Wrap|Line Numbers
  1. SELECT field1, field2, andmoreotherfields, ...
  2. StateCodeDesc = 
  3. case when StateCode = '0' then 'Open'
  4. case when StateCode = '1' then 'Won'
  5. case when StateCode = '2' then 'Lost'
  6. else 'Undefined'
  7. end
  8. from yourTable ....
  9.  

-- CK
Thanks for the help, it helped me a lot. However did that not work for for me, so I tried this :

SELECT StateCode, StateCodeName =
Case StateCode
When '0' then 'Open'
When '1' then 'Won'
When '2' then 'Lost'
else 'Undefined'
end
from MyTableName
Jan 17 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Tryfon Gavriel | last post by:
Hi all I recently noticed when trying to optimise a major query of a chess website I am the webmaster of, that adding an order by for "gamenumber" which is a clustered index field as in for...
10
by: Eric Petruzzelli | last post by:
If I fill my dataset and there is no data. The dataset is still created with zero rows (all columns are there). When I add my first row using the script below, it takes over 2 seconds to add??? If...
3
by: GL | last post by:
Hi, Is there a way to add a field to an existing table using a query of some sort (without needing to manually add a field to the table). I know how to do it with a make table query, but I have...
4
by: Tim Donaldson | last post by:
I have a table generated by a query, and I'd like to add two new field columns to the end or to generate a query which has the same effect. One field is to be called "company" and has the word...
3
by: Robin Thomas | last post by:
I am fairly new to ASP.NET so I think I am missing something fundamental. Anyway, quite often I am pulling data from a database, but then I need to use that data to produce more data. A simple...
1
by: Andrew | last post by:
Hey all, I am very new to ASP.Net (and .Net in general), but that isn't stopping the boss from wanting to begin new projects in it. This latest project has me kinda stumped and after a couple...
16
by: Geoff Jones | last post by:
Hi Can anybody help me with the following, hopefully simple, question? I have a table which I've connected to a dataset. I wish to add a new column to the beginning of the table and to fill...
6
by: Rudy | last post by:
Hi all, I know this is easy, just can't seem to get it. I have a windows form, and a text box, with a value already in it. I need to add that value to a table. It's just one value, so the entire...
1
by: david.goodyear | last post by:
Hi, I have a query that gives me almost the results I want, which is SELECT ai.entry_date as CallTime, ai.agent_login as AgentsLogin, ai.campaign as MarketingCampaign, ai.agent_input2 as...
0
by: uno7031 | last post by:
Help Please!!! Adding 5 Days to another Date in an access query Good Morning, Help please…. I am new to access and trying to write a query that will add 5 days between a RecDate and a...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.