Can SELECT TOP have argument?

Newbie’s question, I believe.
I wanted to make a stored procedure to returns last several rows or last several hundred rows depending on the situation, so I started writing queries in order to copy/paste them into procedure. There are two queries, first works, but
second one shows syntax error in select statement. Can anyone tell me why, and how to go around this?
SELECT TOP 5 * FROM Table1 ORDER BY ID DESC
DECLARE @Counter as int
SET @ Counter = 5
SELECT TOP @ Counter FROM Table1 ORDER BY ID DESC

This works. But I still don?t realize what was wrong with my syntax. Do those () will convert what?s inside parameter to string so parser could read it correctly? What actually is going on here?
It's just the way it is. Originally there was only SELECT TOP n, where the value after TOP had to be a constant. Then they added the ability to have expression, but then they added the parens. This is so that you can say things like:
SELECT TOP (SELECT ... FROM ...) ... FROM
if you feel like.
The old syntax is deprecated but remains for compatibility reasons.
Erland Sommarskog, SQL Server MVP, [email protected]

Similar Messages

  • I can't see the URL for site I am on; instead I have search engines I can select, and type subject to search.

    I have a 2009 MacBook Pro running Snow Leopard.
    I use Firefox v3.6.3
    I don't recall when this happened, or what I could have done to cause it. In the area at the top of the FF window, where the URL is displayed, I have two fields. A small one that is labelled "mozilla.com" with a drop-down menu to the right of it. If I click on the drop down I see a list of websites and their URLs. This may be places I have been, but definitly isn't the most recent sites I have visited. Then to the right of that, taking up more than half of the width of the page is a filed where I can type something to search. There is also a drop down menu at the left end of the field, where I can select what Search Engine I want to use. I can manage that list - add or delete search engines. I prefer to use the standard search window, and be able to see the URL of what ever page I am at. Help!!!

    Try to place the mouse between the small location bar and the large search bar. The mouse pointer should change to a resize pointer that you can drag to the right by pressing the left mouse button to make the location bar wider.

  • TS3376 How do I find the menue where I can select the list of previous phones I have had and my new one ? at the moment it is still set to an old one so everytime I try to set it up it tells me it it's the wrong one - gggrrrrr help please

    How do I find the menue where I can select the list of previous phones I have had and my new one ? at the moment it is still set to an old one so everytime I try to set it up it tells me it it's the wrong one - gggrrrrr help please

    iPods (except for iPod touch) are not linked to any iTunes "account."  They are associated with your iTunes library. The account in iTunes is your Apple ID, and that is used to buy and download content from the iTunes Store.  It is not required to use an iPod.
    The 1st (and 2nd) gen shuffle can only be used with one iTunes library at a time.  When you connect it, iTunes should prompt you to start using it with your iTunes library, and warn that the shuffle's existing content will be erased.  Have iTunes erase the shuffle, and it will be associated with your iTunes library going forward.  You can then add content to your shuffle.
    The need for the previous owner's Apple ID and password should only come up if you are trying to transfer existing content from the shuffle to your iTunes library, AND the previous owner had content purchased from the iTunes Store.  Just cancel out of that step, if iTunes asks.

  • Hi, I have a 7th Gen Ipod Nano and I am unable to delete songs. When synced on the PC I can select tracks but right clicking on them does not give the ability to delete. I have downloaded the latest 1.0.3 software but it did not help.

    Hi,  I have a 7th gen ipod nano and am having a problem with deleting songs. I can select the track in my ipod's library but right clicking does not bring up the option to delet. I have downloaded the latest update for the ipod but this has not solved the issue. Can anyone suggest a remedy? thanks

    Hello Lor100,
    In order to delete or add individual songs from and to your iPod, you'll need to enable 'manual mode' on the device. This will allow you to add and remove exactly the content you desire.
    Managing content manually on iPhone, iPad, and iPod
    http://support.apple.com/kb/HT1535
    Cheers,
    Allen

  • I want to share my itunes with my daughters iPad, we have different usernames, how am I able so she can select tunes individually to transfer

    i want to share my itunes on my I mac with my daughters iPad, we have different usernames, how am I able so she can select tunes individually to transfer to her ipad

    You can sync multiple I tunes account from the same mac.  You will need to authorize the account on the mac.  Then you can share tunes and books across devices.  just take you time when you connect and make sure you are setting up the sync criteria for the right device. 
    If you share apps, the originating itunes account goes with the app, so updating can get problematic, but it is pretty seamless with tunes and books. 
    You can also sync photos from the same master i photo system.
    On each devise, you identify what you want to sync, and I tunes will remember them as seperate entries, so the next time you plug it, it will be starting from what you selected last time.

  • HT1550 i have the newest version of itunes and none of that works!!! i dont know where the advanced menu is and i dont think you can select a song anymore

    I have the newest version of iTunes and none of that works!!! I don't know where the Advanced Menu is. And I don't think you can select a song anymore. I need to make WAV Files to put them on Windows Media Player so i can download music on my Samsung Intensity 2.

    Try placing the iPod in recovery mode and then try to restore. For recovery mode:
    iPhone and iPod touch: Unable to update or restore
    If iTunes still does not see the iPod try:
    iPhone, iPad, or iPod touch: Device not recognized in iTunes for Windows

  • Hi. I've added a new page to my iWeb '08 version 2.0.4 website but can't seem to select the top menu pages to make a rollover color change. I can select them on the original pages. What am I doing wrong?

    Hi. I've added a new page to my iWeb '08 version 2.0.4 website, but can't seem to select the top menu items to make a rollover color change. I can select them on the original pages. What am I forgetting to do?

    Old Toad has a tutorial about changing the colors in the iWeb default menu...
    http://oldtoadstutorials.net/No.24.html
    If you want your website to be found by search engines you would be better to follow Ethmoid's suggestion of creating your own navigation...
    http://www.iwebformusicians.com/iWeb/Navigation.html

  • HT4914 can i select albums while using itunes match or do i have to select individual songs.  also if i can select albums can i scramble the songs?

    Can I select albums while using itunes match or do I have to select individual songs.  If I can select albums will match shuffle?

    Hello georgeandedie,
    It will do your entire library, from there you can play music by albums or just by songs and can shuffle the songs as well.
    iTunes Store: Subscribing to iTunes Match
    http://support.apple.com/kb/HT4914
    Thanks for using Apple Support Communities.
    Regards,
    -Norm G.

  • HT1150 I have two shared printers and I want to be able to select the printer when it is time to print without having to set a default EACH time.  Can I just have a prompt to ask me which printer to use???

    I have two shared printers and I want to be able to select one printer when it is time to print without having to set a default EACH time.  Can I just have a prompt or dialog box that will ask me which printer would you like to use???  The only options I can find are "default" and "Last printer used" which means I must go into the Print & Fax area and change the default EACH time I want to print???  Seems very low tech.....

    junnybug wrote:
    Can I just have a prompt or dialog box that will ask me which printer would you like to use???
    In most cases you get this dialog box every time you print. It is called the print dialog and normally when you print, a print dialog appear showing the printer that is to be used. Which printer you see will be based on what you have set in Print & Fax as you mention. But regardless of what you have set there, you still have the option to change the printer via the print dialog.
    If you are using an application that does not show the print dialog, like MS Word and that stupid "print one copy" print icon in the toolbar, then you can often change the action the print icon uses so that the print dialog appears.

  • What I have to configure in my pc �so I can selecting and copy the ja

    Before i could copy the content of my java console with selecting it and pressing ctrl + c...but now�I can�t :(
    What I have to configure in my pc ...so I can selecting and copy the java console content in a text file?
    Thanks in advance
    Mary

    Excuse me....but i don't have success in that....
    I am using win 2000 server
    jdk 1.4.1.01
    java plug in 1.4.1.01
    I can open the java console.....
    if i select the text and press right clic ....i don't obtain any menus.....
    if i give clic in the title bar (of my java console) i obtain a menu wiht the following obtions:
    Mover
    Tama�o
    Minimizar
    Maximizar
    Cerrar Alt+F4
    And ctrol+c doesn't working.....
    Select the text and press enter...and in the text editor press control+v...and i dont obtain nothing.....:(
    Some ideas or suggestions please?.....
    Thnaks in advance....
    Mary

  • How to select top one in CDS view ?

    I have tried following logic to select top one in CDS view but its giving error -
    define view Cds_View_First_Reference as select  top one CReferredObject from CDSVIEWCROSSREF

    Hi Ruchi,
    since you posted this question in "ABAP in Eclipse" I assume you are asking about CDS in ABAP. This is important because the CDS features sets in ABAP and (native) HANA are different.
    Be that as it may,, SELECT TOP 1 is neither supported in the CDS implementation in ABAP nor in HANA.
    In ABAP you might consider using the min() or max() function together with the appropriate GROUP BY clause in the CDS view (depending on what you want to achieve), but you can also easily "implement" this in the Open SQL statement which selects from your CDS view.
    Using the additions SELECT SINGLE or UP TO 1 ROWS and an appropriate ORDER BY clause in Open SQL, you can achieve the same as SELECT TOP 1.
    Unfortunately there is currently no possibility to define a view which delivers the TOP 1 which you can again use in another view ("view on view").
    Kind regards
    Chris

  • Contacts - how to get faces icon to appear so that I can select photos from iPhoto?

    In Contacts when I try to edit and select a persons photo all I can select from is buttons labelled Defaults, Recents, and Camera.  I have heard there should be a Faces button which would allow me to select photos from iPhoto.  In iPhoto I have applied names to my photos. Any idea why this button does not display for me?  I am on a Mac Pro.
    Thanks

    After posting my question found links to others who have reported the same issue.  The fix for me was to do the following:
    Closed out of both Contacts and iPhoto (may not have been necessary but I did)
    Clicked on Finder application
    Clicked on the GO button at the top of the screen
    Held down the "alt-option" key so that the LIBRARY selection would appear.  Clicked on LIBRARY.
    Clicked on the FILE button at the top of the screen and selected NEW FOLDER.
    Named the folder Images
    Launched the Contacts application.  Edited a contact and when I go to edit the photo I now have the FACES button.

  • SELECT TOP 1 .... ORDER BY

    Hi,
    I have the following statement in SQL SERVER:
    SELECT TOP 1 NAME FROM STUDENT ORDER BYGRADE
    Now, I am trying to translate it ti ORACLE PLSQL, I came up with this statement:
    SELECT NAME FROM STUDENT WHERE ROWNUM=1 ORDER BY GRADE
    It doesn't work. I guess ORACLE generates ROWNUM before the ORDER BY operation...
    How can I have SELECT TOP N ... ORDER BY ... in Oracle the way that I have it in SQL server?
    Any help would be apprecited,
    Alan

    Can you cut and paste exactly what you're doing in a SQL*Plus session? It seems to work for me
    SCOTT @ hp92 Local> create table t as select * from all_objects;
    Table created.
    Elapsed: 00:00:08.40
    SCOTT @ hp92 Local> desc t;
    Name                                                  Null?    Type
    OWNER                                                 NOT NULL VARCHAR2(30)
    OBJECT_NAME                                           NOT NULL VARCHAR2(30)
    SUBOBJECT_NAME                                                 VARCHAR2(30)
    OBJECT_ID                                             NOT NULL NUMBER
    DATA_OBJECT_ID                                                 NUMBER
    OBJECT_TYPE                                                    VARCHAR2(18)
    CREATED                                               NOT NULL DATE
    LAST_DDL_TIME                                         NOT NULL DATE
    TIMESTAMP                                                      VARCHAR2(19)
    STATUS                                                         VARCHAR2(7)
    TEMPORARY                                                      VARCHAR2(1)
    GENERATED                                                      VARCHAR2(1)
    SECONDARY                                                      VARCHAR2(1)
    SCOTT @ hp92 Local> create index idx_t on t( object_id );
    Index created.
    Elapsed: 00:00:00.78
    SCOTT @ hp92 Local> analyze table t compute statistics for all indexed columns;
    Table analyzed.
    Elapsed: 00:00:00.53
    SCOTT @ hp92 Local> set autotrace on;
    SCOTT @ hp92 Local> select *
      2    from (select * from t order by object_id)
      3   where rownum < 2;
    OWNER                          OBJECT_NAME                    SUBOBJECT_NAME
    OBJECT_ID DATA_OBJECT_ID OBJECT_TYPE        CREATED   LAST_DDL_ TIMESTAMP           STATUS  T G S
    SYS                            DUAL
           222            222 TABLE              12-MAY-02 12-MAY-02 2002-05-12:16:20:50 VALID   N N N
    Elapsed: 00:00:00.13
    Execution Plan
       0      SELECT STATEMENT Optimizer=CHOOSE
       1    0   COUNT (STOPKEY)
       2    1     VIEW
       3    2       TABLE ACCESS (BY INDEX ROWID) OF 'T'
       4    3         INDEX (FULL SCAN) OF 'IDX_T' (NON-UNIQUE)
    Statistics
              0  recursive calls
              0  db block gets
              3  consistent gets
              1  physical reads
              0  redo size
           1142  bytes sent via SQL*Net to client
            511  bytes received via SQL*Net from client
              2  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
              1  rows processedJustin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • Looking for the oracle equivalent of T-SQL 'SELECT TOP n'

    Hi,
    I'm looking for the Oracle equivalent of T-SQL 'SELECT TOP n'
    and can't find any. There is SAMPLE(n) function but it supposed
    to pick up random values and I'm not sure if it's possible to
    make it select top values. Please help 8-)
    Thanx

    Hi Marina.
    Oracle does not have a functionality like SQL Server for TOP
    selection. The ROWNUM option should be used with great care and
    you may get unreliable results.
    Try looking at Metalink
    Doc ID: 291065.999
    Doc ID: 267329.999
    - They discuss this issue, and solutions.

  • In previous version F6 can Edit url but new version can't it have new hot key or remove it?

    in previous version F6 can Edit url but new version can't it have new hot key or remove it??

    F6 focuses the first selectable element.<br />
    If "Tabs on Top" is selected then the active tab is selectable, so the location bar is not selected.<br />
    Press F6 to set focus on the Tab bar and press the Tab key until the location bar gets focus.
    To get the 3.6 behavior uncheck "Firefox button > options > [] Tabs on Top" or use Alt + D or Ctrl + L

Maybe you are looking for

  • ======= Xtended Configuration Management-Runtime Error=========

    Hi Experts, Need your immediate response/feedback for the below Error explained brieflyu2026 We are able to download/replicate the Products & KB objects into CRM System from R3. After that we have done the followings steps to configure the VC product

  • Zero Decimal values in AL11 file download

    Hi Experts, We have a program to download data into XLS file in AL11 application server. We have a currency column to be passed on to the file. The issue here is I have a decimal value like 201.30 and 200.00 but these values are downloading in AL11 a

  • Need Information

    We have faced a problem in (Flash 8) Tween Class under mx.transitions package for our specific project. Tween  Class is not working properly when we are loading multiple swf(AS2) files in flex application and communicate via local connection. To reso

  • SQL Function to trim characters

    Hi! Can someone help me with writing SQL Function which receive a string and return it with all the below ASCII characters values removed: chr(n)>31 AND chr(n)<48 OR chr(n)>57 AND chr(n)<65 OR chr(n)>90 AND chr(n)<97 OR chr(n)>122 AND chr(n)<128 Than

  • FAQ: Why won't After Effects import my PSD file as a composition but flattens it?

    from the "Preparing and importing Photoshop files" section of After Effects Help: "Layered Photoshop (PSD) files need to be saved in RGB or Grayscale color mode for After Effects to import them as a composition and to separate the layers. CMYK, LAB,