•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the MS SQL section within the Web Development category of DaniWeb, a massive community of 456,588 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,612 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MS SQL advertiser: Programming Forums
Views: 1076 | Replies: 3
![]() |
•
•
Join Date: Nov 2007
Posts: 5
Reputation:
Rep Power: 0
Solved Threads: 0
Hello, I have a quick question. I'm currently using MS SQL 2005.
I have a main table which has many fields. I created a view#1 which imports all the rows from the main table but I only select the "City" field, "PurchaseDescription" field and a "Cost" field. Only the city name is unique. There are a total of 50 different city names, and each name can have more than one "PurchaseDescription" each with an associated "Cost". I would like to create a second view#2 with an added field called "Cost2". I want "Cost2" to contain the same value as the "Cost" value. However if the "PurchaseDescription" equals to "USB" then "Cost2" should be assigned the value of "Cost" multiplied by -1. If the "PurchaseDescription" content isn't equal to "USB" then "Cost2" will have the save value as "Cost".
For example,
The view#1 will have the following rows & fields (I had to pad the field with dots just to make the output look viewable on this thread)
City..............PurchaseDescription............Cost
--------------------------------------------
LA.................desk................................4.5
LA.................USB.................................5.0
LA.................USB.................................6.0
SD................chair.................................4.0
SD................door.................................10.0
The view#2 should have the following rows and fields
City..............PurchaseDescription............Cost.......Cost2
---------------------------------------------------------
LA.................desk................................4.5....... 4.5
LA.................USB.................................5.0....... -5.0
LA.................USB.................................6.0....... -6.0
SD................chair.................................4.0....... 4.0
SD................door.................................10.0....... 10.0
I don't mind if I have to use functions or more than 2 views to solve my problem. I jus need a final view that would look like view#2.
Could you please help if you can?
Thank you very much for your time and have a safe Halloween!
I have a main table which has many fields. I created a view#1 which imports all the rows from the main table but I only select the "City" field, "PurchaseDescription" field and a "Cost" field. Only the city name is unique. There are a total of 50 different city names, and each name can have more than one "PurchaseDescription" each with an associated "Cost". I would like to create a second view#2 with an added field called "Cost2". I want "Cost2" to contain the same value as the "Cost" value. However if the "PurchaseDescription" equals to "USB" then "Cost2" should be assigned the value of "Cost" multiplied by -1. If the "PurchaseDescription" content isn't equal to "USB" then "Cost2" will have the save value as "Cost".
For example,
The view#1 will have the following rows & fields (I had to pad the field with dots just to make the output look viewable on this thread)
City..............PurchaseDescription............Cost
--------------------------------------------
LA.................desk................................4.5
LA.................USB.................................5.0
LA.................USB.................................6.0
SD................chair.................................4.0
SD................door.................................10.0
The view#2 should have the following rows and fields
City..............PurchaseDescription............Cost.......Cost2
---------------------------------------------------------
LA.................desk................................4.5....... 4.5
LA.................USB.................................5.0....... -5.0
LA.................USB.................................6.0....... -6.0
SD................chair.................................4.0....... 4.0
SD................door.................................10.0....... 10.0
I don't mind if I have to use functions or more than 2 views to solve my problem. I jus need a final view that would look like view#2.
Could you please help if you can?
Thank you very much for your time and have a safe Halloween!
•
•
Join Date: Feb 2007
Location: Bangalore,India
Posts: 1,445
Reputation:
Rep Power: 4
Solved Threads: 87
![]() |
•
•
•
•
•
•
•
•
DaniWeb MS SQL Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- i need to add function for add, subtract, multiply and division. (C++)
- How to create multiple toggle field codes in Word. (MS Access and FileMaker Pro)
- Synthetic field (Java)
- field lengths (was: help urgent ) (Java)
- FIeld width zero? (Visual Basic 4 / 5 / 6)
Other Threads in the MS SQL Forum
- Previous Thread: Identity column
- Next Thread: retrieving a string into mathematical expression



Linear Mode