A column that's calculated from the previous three columns

I have written this query and it runs perfectly:
============================================================
Select ProductName, ListPrice, DiscountPercent, ListPrice - DiscountPercent AS DiscountAmount
From Products
==================================================================
Now I need  to add this line to this query: DiscountPrice calculated from (ListPrice - DiscountAmount).   But I keep getting errors:
Select ProductName, ListPrice, DiscountPercent, ListPrice - DiscountPercent AS DiscountAmount
ListPrice - DiscountAmount AS DiscountPrice
(Get Errors on ListPrice; Msg 102, Level 15, State 1, Line 3
Incorrect syntax near 'ListPrice'.)
From Products

You need to repeat the ListPrice formula in your DiscountPrice formula (the most efficient way to handle this formula).  The alias ListPrice is not available until after the select is complete.
See the
http://www.sql.co.il/books/insidetsql2008/Logical%20Query%20Processing%20Poster.pdf (Logical Query Processing).
Russel Loski, MCT, MCSE Data Platform/Business Intelligence. Twitter: @sqlmovers; blog: www.sqlmovers.com

Similar Messages

  • Display only data different from the previous row

    Hello,
    I will use a simple example to explain what I would like to do with a query.
    I have a table 'test' with 4 columns (col1, col2, col3, col4).
    The table 'test' contains the following data:
    A  B  C  D
    A  E  C  D
    A  F  G  D
    K  F  G  HI would like to create a query ordered on the first column with the following result:
    A  B  C  D
       E
       F  G
    K        HOnly data that are different from the previous row have to be displayed.
    Do you have ideas on how to do this.
    Thanks for your help

    SQL> l
      1  select
      2  decode(a,lag(a) over (order by a),null,a) a,
      3  decode(b,lag(b) over (order by a),null,b) b,
      4  decode(c,lag(c) over (order by a),null,c) c,
      5  decode(d,lag(d) over (order by a),null,d) d
      6  from
      7  (
      8  select 'A' a,'B' b,'C' c , 'D' d from dual
      9  union
    10  select 'A' a,'E' b,'C' c , 'D' d from dual
    11  union
    12  select 'A' a,'F' b,'G' c , 'D' d from dual
    13  union
    14  select 'K' a,'F' b,'G' c , 'H' d from dual
    15* )
    SQL> /
    A B C D
    A B C D
      E
      F G
    K     H

  • When I update itunes it deletes the library file, and when I restore that file from the previous libraries or my backup, itunes will run but tell me "the iTunes library file cannot be saved. A folder was specified instead of a file" How do I fix this?

    When I update itunes it deletes the library file, and when I restore that file from the previous libraries or my backup, itunes will run but tell me "the iTunes library file cannot be saved. A folder was specified instead of a file" How do I fix this?

    Hi there Br0x,
    You may want to try rebuilding the iTunes library as an initial troubleshooting step. Take a look at the article below for more information.
    iTunes: How to re-create your iTunes library and playlists
    http://support.apple.com/kb/ht1451
    -Griff W.

  • I accidently closed my window with all my app tabs, now the only window that opens was a 2nd one I had open. How do I get back all my app tabs from the previous window, and why didn't it give me the usual warning you are closing more than one tab?

    I accidently closed the window with all my frequently used app tabs, now the only window that opens was an extra one I had opened. How do I get back all my app tabs from the previous window, and why didn't it give me the usual warning you are closing more than one tab? edit
    Details

    Then the (App) tabs from that window are lost unless you can restore an older copy of the sessionstore.js file (Time Machine?) that has that lost window.
    *http://kb.mozillazine.org/sessionstore.js

  • HT201272 How can we delete apps, etc from the Previously Purchased list so that they don't show there anymore?

    How can we delete apps, etc from the Previously Purchased list so that they don't show there anymore?

    You can't currently permanently delete purchases, all you can do is hide them so that they are less visible : hiding and unhiding purchases

  • I have a classic iPod with songs that were put on it from a different computer. If I plug it up to my computer, will it keep the songs that were originally on it from the previous computer AND allow me to put new songs on it from my computer?

    I have a classic iPod with songs that were put on it from a different computer. If I plug it up to my computer, will it keep the songs that were originally on it from the previous computer AND allow me to put new songs on it from my computer?

    No.  Your iPod is designed to sync with one computer/iTunes library at a time. If you try to sync it with a new computer/iTunes library, the contents currently on the iPod will be erased and replaced with content from the new library.  So you'll want to copy what is currently on the iPod over to your new iTunes library first before syncing it.
    See this older post from another forum member Zevoneer covering the different methods and software available to assist you with the task of copying content from your iPod back to your PC and into iTunes.
    https://discussions.apple.com/thread/2452022?start=0&tstart=0
    B-rock

  • Filter a List for data from the Previous Month

    Hello,
    I have audit data for each month of the year.  At the beginning of one month I pull a report from the previous month.  I would like to have a view in my SharePoint list that shows only the data from the previous month.
    I am not a programmer or developer, so I was wondering if this is possible without out of the box tools.
    Here is what I have done so far:
    Created two calculated columns to find the start and end date of the previous month
              Previous Month Start =DATE(YEAR([Date of Review]),MONTH([Date of Review])-1,1)
              Previous Month End   =DATE(YEAR([Date of Review]),MONTH([Date of Review]),0)
    I have verified these two calculations do show the correct dates. 
    So I can generate the dates, but I don't know how to set up a view filter that will show only data from the previous month. 
    Please help.

    What you need is the calculated column to display the start and the end of the next month, not the previous month. Then you can do a view filter where Start<Today & End>Today.
    EX: If you have a document with date 15-03-2014, you need to save the dates 01-04-2014(start) and 30-04-2014(End).
    Then If Start < [Today] and End > [Today], you can show the document

  • I have purchased itunes match but the cloud will not load on my ipad 4.the only music that will show up is stuff that i bought from the itunes store.any ideas on how to get this to work?

    i have purchased itunes match but the cloud will not load on my ipad 4.it works on my iphone 5 & it originally worked on my ipad.the only music that will show up is stuff that i bought from the itunes store.any ideas on how to get this to work?

    On the MBP, in iTunes, switch to Song view and enable the iCloud Status column by pulling down View > View options and selecting the option for "iCloud Status." Close the small window. Look for any tracks that have a status of "waiting." If you see several of them disable iTunes Match while holding down the Option key. Quit iTunes, wait a few seconds, then open it again and turn iTM back on. Let it compelete the scan. Wait until all tracks that are "waiting" have a status of either "matched" or "uploaded."
    On the iPad, turn off iTunes Match then launch the Music app and let the contents clear out. Power cycle the iPad for good measure, then re-enable the service once all the tracks in iTunes have been processed.

  • How to get a value from the previous element (XSLT/XPATH gurus ahoy!)

    Hi All,
    I am building an RTF template for a "letter of reference"-report. Sometimes there are several rows in the data, that need to be printed as one. This is due to consecutive temporary contracts, which will be printed out as one period of service.
    Here's a simplified data example to illustrate the problem.
    <ROW>
    <START_DATE>01-01-1980</START_DATE>
    <END_DATE>01-01-1988</END_DATE>
    </ROW>
    <ROW>
    <START_DATE>01-01-1988</START_DATE>
    <END_DATE>01-01-1990</END_DATE>
    </ROW>
    <ROW>
    <START_DATE>01-01-2000</START_DATE>
    <END_DATE>01-01-2005</END_DATE>
    </ROW>
    With the data above, I should print two lines:
    01-01-1980 - 01-01-1990
    01-01-2000 - 01-01-2005
    I need to compare START_DATE of an element (except for the first one) with the END_DATE of the previous element, to find out whether to print the END_DATE for that element or not. How can I get that value from the previous element?
    Thanks & Regards, Matilda

    use this to get the following End_date
    <?following-sibling::../END_DATE?>
    Try this
    <?for-each:/ROOT/ROW?>
    ==================
    Current StartDate <?START_DATE?>
    Current End Date <?END_DATE?>
    Next Start Date <?following-sibling::ROW/END_DATE?>
    Previous End Date <?preceding-sibling::ROW[1]/END_DATE?>
    ================
    <?end for-each?>
    o/p
    ==================
    Current StartDate 01-01-1980
    Current End Date 01-01-1988
    Next Start Date 01-01-1990
    Previous End Date
    ================
    ==================
    Current StartDate 01-01-1988
    Current End Date 01-01-1990
    Next Start Date 01-01-2005
    Previous End Date 01-01-1988
    ================
    ==================
    Current StartDate 01-01-2000
    Current End Date 01-01-2005
    Next Start Date
    Previous End Date 01

  • HT1311 To create a new apple ID, if I sign out of the current Apple ID account, and then sign in with a newly created account, will I lose any songs or apps on my phone or computer that were downloaded from the old apple ID?

    To create a new apple ID, if I sign out of the current Apple ID account, and then sign in with a newly created account, will I lose any songs or apps on my Iphone and Macbook Pro computer that were downloaded from the old apple ID?

    No, you will not loose anything.  However, if you ever need to update any of that previously purchased content, or re-download it, you will have to use the older AppleID.  Purchases are permanently tied to the AppleID you use when making the purchase.

  • I have two iTunes accounts and was wondering if i can merge them together. I've a new macbook pro and haven't plugged my iPhone in it yet in fear of losing my songs from the previous account.

    I have two iTunes accounts and was wondering if i can merge them together. I've a new macbook pro and haven't plugged my iPhone in it yet in fear of losing my songs from the previous account.

    Go to the Music section of your Library (very top-left corner) and see if your songs are there. The "Purchased" playlist may have been deleted or gotten corrupted, but if that happens it's not a big deal because your music should still be in your main Music Library.
    If your music is NOT in the Music section of your Library, then go to the iTunes Store homepage and find the Quick Links list on the right side. At the top of that list, click Purchased and you can redownload all of your previous content that you might have lost.

  • TS3577 I want to erase the new Garage band and convert to my old one. As soon as it downloaded, I Lost all of my songs from the previous Sessions,HOW DO I GET THEM BACK?

    I want to erase the new Garage band and convert to my old one. As soon as it downloaded, I Lost all of my songs from the previous Sessions,HOW DO I GET THEM BACK?

    MacBook Pro, iOS 7.0.6
    Your signature lists both, Mac and iOS device - are you asking about GarageBand on your Mac or your iPhone/iPad?
    If you are asking about the upgrade from GarageBand '11 to GarageBand 10.0 on your Mac, the old GarageBand version should still be installed. The installer will have moved GarageBand '11 to a separate folder "GarageBand 6.0.5" in your Applications folder. Open this folder and click "GarageBand".  Does this version still see your old projects?  If not, type ".band" into the Spotlight searchfield in the upper right corner of your screen. Does that sfind your missing projects?
    If you are asking about GarageBand on iPad/iPhone, there it is not possible to restore the previous version after you upgraded. And I do not see, how this upgrade could have deleted your projects. Have they completely vanished, or can you not open them any longer? If your projects have vanished, restore your device from your backup: See:  iCloud: Backup and restore overview
    -- Léonie

  • Firefox 4 opens multiple windows (15-25) when opening and only once in a blue moon will remember the tabs from the previous session in the first of the multiple windows.

    When I open Firefox 4 from either the icon or from a link from e-mail or some other place, multiple windows open up. Usually between 15 and 25 of them. I'm running Windows 7 Ultimate on both my laptop and desktop and have the same issue with both. I tried disabling the plug-ins one by one since they were all up-to-date, to no avail. My laptop has an upgraded version of Windows while my desktop has a clean install. I tried uninstalling Firefox 4 and going back to 3 and then the same thing started happening withe v3 when it wasn't before. Only sometimes, on rare occasions, will the first window that opens have my tabs from the previous session. Most times all the windows have one blank tab. The first one I can tell 'cause it does not have the orange Firefox menu button (since I'd chosen to show the Menu Bar) while the first window shows the menu bar. The troubleshooting info is from my laptop only.

    Unless the schedule it's running on is every single time I open Firefox (including closing it & reopening it right away), I don't think that's the case. Also, I don't have any of these issues on the PC I switched back to v3.6 on. That one runs smoothly whether I run Ccleaner, registry optimizers, clear the cache & history or whatever. I thought after you first gave me the answer of deleting the session files that they must've got corrupted during the upgrade, but it seems that v4 just doesn't do a good job of retaining or maintaining those files without getting them corrupt or something.
    If this is not an issue with everyone & I'm having it on both my PCs, then v4 has an issue with something that I install on my PCs that, I guess, many others don't although I don't know what that could be and I use everything I install or have running. So, I'm just going back to what works without having to dismantle my config one prog at a time to try to find what v4 may be finicky about.
    By the way, I did check & couldn't find any cleaners that run automatically on my PCs.

  • I just bought the AIrport Extreme to replace an older Linksys wireless g router. But I am still getting a fairly low signal, not showing much improvement from the previous router. What gives?

    I just bought the airport extreme router to replace my older linksys g router because of a poor signal. Now that I have the new router running, I'm not seeing much improvement from the previous router! What gives?

    I too recently bought the Extreme to replace an old Linksys G and discoverd that the range of the new Extreme was surprising less than the Linksys.
    Nothing had changed otherwise; both routers were installed in the same place (on floor, under a cabinet in the middle of my house).
    I returned the Airport Extreme to Amazon and bought another (the latest version), and the same problem exists, i.e., I can't get a signal at the corners of my small home with the Airport, where I once could with the Linksys.
    I'm puzzled, but think that difference must be that the Linksys has 2 large external antennas and the Extreme's antennas are mounted internally.
    I've also noticed that Apple sells a wall mount for the Airport Extreme and am assuming this is to get the Airport up and out into the open in order to improve its 'send and receive' characteristics, no?
    If your Extreme is hidden in a cabinet or under some piece of furniture, I suggest you move it into the open and see if this helps extend its range.
    Hope this helps.
    John

  • Is there a way to get the calculator from the dashboard to appear along with other programs?  Can anyone recommend a calculator which will work as a stand alone app?

    AS it stands now, in order to use the calculator that comes with the Dashboard, you cannot read from a list of numbers in, lets say, word or excel. The dashboard is full screen and nothing can stand along side it. Is there a way to get the calculator from the dashboard to appear along with other programs?  Can anyone recommend a calculator which will work as a stand alone app?

    there is one, just search with spotlight "Calculator".
    It works great!
    Hope this helps.

Maybe you are looking for