Why I cannot use RowID in where clause but can use it in order by clause

I am on SQL Server 2008.
1. If I use
SELECT (ROW_NUMBER()  over
(order by ImportId, ScenarioId, SiteID, AssetID, LocalSKUID, WEEKID, MonthID)) RowID, * 
  FROM [JnJ_Version1].[dbo].[td_Production_Week]
  order by RowID
Statement works
But
2. If I use
SELECT (ROW_NUMBER()  over
(order by ImportId, ScenarioId, SiteID, AssetID, LocalSKUID, WEEKID, MonthID)) RowID, * 
  FROM [JnJ_Version1].[dbo].[td_Production_Week]
  where  RowID > 10000
I get error, RowID is an invalid column Name why? How to correct query 2.

This is due to the logical evaluation order of a SELECT statement. Logically, a SELECT statement is computed in the order:
FROM (which includes JOIN)
WHERE
GROUP BY
HAVING
SELECT
ORDER BY
OFFSET
Thus, you can use what is defined in the SELECT list in the ORDER BY clause, but not in the WHERE clause.
In the case of row_number(), this has immediate repurcussions. row_number() is computed from the rows as they arrive the SELECT clause, and if you then you would filter on the value in the WHERE clause you would be going round in circles.
To do what you are looking for, you use a nested table, for instance with a CTE:
WITH numbering AS (
   SELECT (ROW_NUMBER()  over
(order by ImportId, ScenarioId, SiteID, AssetID, LocalSKUID, WEEKID, MonthID)) RowID, * 
  FROM [JnJ_Version1].[dbo].[td_Production_Week]
SELECT *
FROM   numbering
WHERE  RowID > 10000
Erland Sommarskog, SQL Server MVP, [email protected]

Similar Messages

  • I can't use this query on 10G, but can use on 9i

    I have ever used bellow query and no error
    SQL>select so.* from bsowner.sales_orders so left join bsowner.relation_address rla on (so.customerid = rla.relationid and so.delivery_addressid = rla.addressid ) and rla.addresstype = (select code from bsowner.tab_addtyp where config1=3)
    When I use on 10G, I can't query
    1* select so.* from bsowner.sales_orders so left join bsowner.relation_address rla on (so.customerid = rla.relationid and so.delivery_addressid = rla.addressid ) and rla.addresstype = (select code from bsowner.tab_addtyp where config1=3)
    SQL> /
    select so.* from bsowner.sales_orders so left join bsowner.relation_address rla on (so.customerid = rla.relationid and so.delivery_addressid = rla.addressid ) and rla.addresstype = (select code from bsowner.tab_addtyp where config1=3)
    ERROR at line 1:
    ORA-01799: a column may not be outer-joined to a subquery
    Help me,Please
    Why I can't use this on 10G?
    when i change = to in , i can use
    but i don't want to change
    help me for the reason

    I don't this gonna work on 9i either.
    Chang your query to
    select so.* from bsowner.sales_orders so left join bsowner.relation_address rla on (so.customerid = rla.relationid and so.delivery_addressid = rla.addressid )
    Where
    rla.addresstype = (select code from bsowner.tab_addtyp where config1=3)

  • Can't use Photoshop on my macbook, but can use Photoshop app on my windows laptop?

    Hi guys
    Basically I recently purchased a macbook pro (hooray!) and I'm having trouble downloading the photoshop app. I can use it no problem on my Toshibe, which is where I first installed creative cloud, but for some reason it looks like it doesn't exist on my creative clod for mac?
    Any help would be greatly appreciated keen to get photoshopping on my awesome new pro!
    Thanks
    Sarah

    HI Sarah,
    Are you receiving any errors when downloading and installing? Here is a network activation help page. Go thru the steps in the link to ensure that your computer can communicate with the Adobe servers. http://helpx.adobe.com/x-productkb/policy-pricing/activation-network-issues.html
    Thanks
    Scott

  • Cannot access BTyahoo mail using safari or google chrome but can using Firefox. Any ideas why and how it is fixed

    I have recently signed up to BT but find that I cannot access BTyahoo mail using either safari or google chrome - the pages are just not available. But it works with Firefox. Any ideas why and how it can be fixed?

    Hi, this has worked for a few...
    Make a New Location, Using network locations in Mac OS X ...
    http://support.apple.com/kb/HT2712
    10.7 & 10.8…
    System Preferences>Network, top of window>Locations>Edit Locations, little plus icon, give it a name.
    10.5.x/10.6.x/10.7.x instructions...
    System Preferences>Network, click on the little gear at the bottom next to the + & - icons, (unlock lock first if locked), choose Set Service Order.
    The interface that connects to the Internet should be dragged to the top of the list.
    10.4 instructions...
    Is that Interface dragged to the top of Network>Show:>Network Port Configurations.
    If using Wifi/Airport...
    Instead of joining your Network from the list, click the WiFi icon at the top, and click join other network. Fill in everything as needed.
    For 10.5/10.6/10.7/10.8, System Preferences>Network, unlock the lock if need be, highlight the Interface you use to connect to Internet, click on the advanced button, click on the DNS tab, click on the little plus icon, then add these numbers...
    208.67.222.222
    208.67.220.220
    Click OK.

  • I cannot import my photos to iPhoto but can using another user sharing the same library.

    I am trying to import my photos on my main user account on my iMac to iPhoto 11.  I am running Mac OS X Version 10.7.5
    When I try to upload using my main user account it will not upload the photos.  It gives an error message "iPhoto cannot import your photos because there was a problem downloading an image.  I also get urecognised file format from my Cannon SLR.  The crazy thing is, I share the same library with my wifes user account on the same Mac and the images upload without any issues.  I can see them in my user account but when I try to open the landscape files I get an exclamation mark on a black background.
    Any help with this will be appreciated.

    The exclamation mark means that iPhoto has lost/broken the file path to the original/master file. Apply the two fixes below in order as needed to reair the library:
    Fix #1
    1 - launch iPhoto with the Command+Option keys held down and rebuild the library.
    2 - run Option #4 to rebuild the database.
    Fix #2
    Using iPhoto Library Manager  to Rebuild Your iPhoto Library
    1 - download iPhoto Library Manager and launch.
    2 - click on the Add Library button and select the library you want to add in the selection window..
    3 - Now that the library is listed in the left hand pane of iPLM, click on your library and go to the Library ➙ Rebuild Library menu option.
    4 - In the next  window name the new library and select the location you want it to be placed.
    5 - Click on the Create button.
    Note: This creates a new library based on the LIbraryData.xml file in the library and will recover Events, Albums, keywords, titles and comments.  However, books, calendars, cards and slideshows will be lost. The original library will be left untouched for further attempts at fixing the problem or in case the rebuilt library is not satisfactory.
    OT

  • Why i cannot connect my dvd writer and cd writer using ide2???

    why i cannot connect my dvd writer and cd writer using ide2???
    can anyone help?

    Why is it that i cannot connect both the harddisk to IDE1 and both writers to IDE2 or IDE3?
    Currently i am only connecting my Samsung 80G and Sony DRU810A to IDE1.
    Can anyone help?
    PowerLogic 450W
    Intel Pentium 4 2.8Ghz FSB 533/775
    512Mhz Kingston PC - 4300 DDR2 533 CL4
    MSI 915P Neo2 FR
    Samsung 80G 7200rpm 2MB
    Maxtor 40G 7200rpm 2MB
    Sony DRU810A 16xDVD+-R (8xDL)
    Iomega cdrw 40x12x40

  • Why cant i log on my FB? i can use other website. what should I do?

    why cant i log on my FB? i can use other website. what should I do?
    If its ok, plz send the solution to my Email:
    <Email Edited by Host>

    I was traveling China, which FB r blocked.
    But now i come back to the place where i used to be logging on FB, but it doesnt work now.
    Should I change my IP or something?

  • This device cannot find enough free resources that it can use. (Code 12)

    Got the above error when i insert a firewire card with via chipset. I have update the firewire driver by picking a list of device driver from my computer and though it prompt me to restart but yet it still shows the yellow exclamation mark and next i update it through online, same thing it prompt me to restart which i did but sad to say it shows the yellow exclamation again
    When i check under properties>general tab, it says the following Quote
    This device cannot find enough free resources that it can use. (Code 12)
    If you want to use this device, you will need to disable one of the other devices on this system.
    You need to restart your computer before the changes you made to this device will take effect.
    Click 'Check for solutions' to send data about this device to Microsoft and to see if there is a solution available.
    As far as i know the irq in bios setup is all set as auto and the total there's 4 pci slot and only 1 that is using, so how can it be resources being used up?? 
    Fyi i'm using Msi P35 neo3 mobo with vista ultimate sp1

    Under device manager> VIA OCHI Compliant IEEE 1394 host controller> right click it and choose update driver follow by choosing the option of search automatically for updated software (window would search your computer and the internet for the lastest driver software for your device)
    Once done i reboot and next bingo.... the yellow exclamation was no longer there, infact it was quite wierd when i try updating online, as the very first time it doesn't work but wouldn't know why the second time it does  

  • When i plug my ipod into my computer it is not recharging.  The computer doesn't even acknowledge that it is plugged in. Any ideas why? It does have power left so i can use it but i want to recharge it of course.  Any input is appreicated.

    When i plug my ipod into my computer it is not recharging.  The computer doesn't even acknowledge that it is plugged in. Any ideas why? It does have power left so i can use it but i want to recharge it of course.  Any input is appreicated.

    Plug it into the wall using the supplied charger.
    Barry

  • I, work on dell laptop latitudes version 7, win 7 64 bit, ssd disk, 16 gb ram. i receive the error 12 This device cannot find enough free resources that it can use. please help

    I, work on dell laptop latitudes version 7, win 7 64 bit, ssd disk, 16 gb ram.
    i receive the error 12 This device cannot find enough free resources that it can use. please help

    1. You have placed problem in wrong forum, or use different Windows operating system
    2. Double check your resources, namely in Disk manager. What is free space on HDD?
    Regards
    Milos

  • Query can't include an "ORDER BY" clause when having column heading sorting

    I'm getting the following error when I try to include "ORDER BY" in my sql statement :
    "Your query can't include an "ORDER BY" clause when having column heading sorting enabled"
    I have used other sql statements with "ORDER BY" but this is the first time I have come across this and I don't understand why it's going wrong. Does anyone have a suggestion as to how I could fix it? Here is one of the sql statements which I have tried which is giving me the error:
    select "ID_NUMBER",
    "PROJECT_NAME",
    "PROJECT_TYPE",
    "OWNER",
    "PRIORITY",
    "STATUS",
    "END_DATE",
    "COMMENTS"
    from "PROJECT"
    WHERE "STATUS" != 'Completed' AND "STATUS" != 'Cancelled'
    ORDER BY "END_DATE"
    Regards,
    Ed.

    You must deselect column heading sorting that is in the page "Report Attributes" .This is a check box placed on the same line of the element of the report.
    bye

  • Can i assign an 'order by' clause dynamically in forms ??

    I know it's possible to assign an 'order by' clause in reports with lexical parameter.
    for example..
    select A
    from TABLE
    where A is not null
    &V_ORDERBY
    In this, v_orderby might be 'order by name' like that,,,
    can i assign an 'order by' clause dynamically IN FORMS ??
    If you understan my question, please answer to me,,,ㅜㅜ

    Have you tried this build-in function?
    SET_BLOCK_PROPERTY('[BLOCK_NAME]', ORDER_BY, 'SORTCOL1, SORTCOL2...');
    Where 'SORTCOL1, SORTCOL2...' are the table columns name.

  • I brought iphone 4s from UK and using it in India. But while using SIRI, it says, it cant find anything in India. how can I resolve this issue ?

    I brought iphone 4s from UK and using it in India. But while using SIRI, it says, it cant find anything in India. how can I resolve this issue ?

    There are some countries where FaceTime is not option on the iPhone iOS5, and there is no way to put it back, if you bought an iPhone in one of these countries.
    Apple Tells Us Exactly Where FaceTime Is Not Available

  • So my iphone 4 that is using ios5 keeps freezing when i want to dial, or receive call. i can use all my other apps but cant use the phone to call because the freezing problem. i know some people that are having the same problem too. what can i do?

    so my iphone 4 that is using ios5 keeps freezing when i want to dial, or receive call. i can use all my other apps but cant use the phone to call because the freezing problem. i know some people that are having the same problem too. what can i do?

    I got the same problem. The percentage of getting this problem is around 10% of all my dial/receive calls.
    The problem usually appears when I receive calls. The phone app will freeze, and I cannot dial or receive calls even I closed the phone app, however, most other apps work properly.
    Once this problem happens, I will not be able to turn off the phone by holding sleep button, the only way I can get rid of it is holding sleep and home button at the same time to reset the iphone.

  • Hi,  If I have 1 license for creative cloud, will it possible to install in 2 computers (1 laptop and 1 desktop)?  When I am in the office I can use desktop and at home I can use laptop? At the same time I will be using only one devise. Will that be possi

    Hi,  If I have 1 license for creative cloud, will it possible to install in 2 computers (1 laptop and 1 desktop)?  When I am in the office I can use desktop and at home I can use laptop? At the same time I will be using only one devise. Will that be possible?  Thanks

    Yes. Yes. Yes.
    Mylenium

Maybe you are looking for

  • Naming Services cannot work well!!!

    Hi, I have configured the AM2005Q4 and Policy agent with apache, apache http.conf file is like ProxyRequests Off <Proxy *> Order deny,allow Allow from all </Proxy> ProxyPass /hzycportal http://exchange.hzliqun.com:8013/hzycportal ProxyPassReverse /hz

  • How to find out number of concurrent users  connectd to a site?

    I would like to find out the number of concurrent users on my site. What is the best way to do it? This is how I implement it currently: I have a HashSet object in the session. whenever a user visits the page, i added the user's sessionID to the Hash

  • Mac file name restrictions/special characters

    What are the Mac OS file name restrictions? What are the special characters to avoid? Is this a legitimate file name? Are the colons allowed? /Users/Joe/Desktop/MyDocument 3:2:06.xls   Windows XP Pro  

  • Help! how to use sequence in in Oracle

    i have a table name account and i want the id column used the sequence XJ.ID so how to modfiy the .jdo file? here is the .jdo file <?xml version="1.0" encoding="UTF-8"?> <jdo> <package name="test"> <class name="Account" objectid-class="AccountId"> <e

  • Urgent - import an html( which is in cluster) in jsp

    Hi All, here is my problem: 1. I have a sample.jsp in app server. 2. I have add.html in web server. 3. these two servers are clustered 4. i want to import this static html in to jsp. i am unable to include html file in webser i tried like this <jsp:i