Author |
Topic |
jane0829
Starting Member
6 Posts |
Posted - 2013-11-25 : 13:29:00
|
Hi ALLI am trying to get the current row number using this:SELECT ROW_NUMBER() OVER (ORDER BY QUANTITY) FROM RDR1 WHERE Row = CurrentRowHowever i got error message says row is an invalid column namePlease advise. |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-11-25 : 13:31:52
|
this is enoughSELECT ROW_NUMBER() OVER (ORDER BY QUANTITY)AS Rno,* FROM RDR1 ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
jane0829
Starting Member
6 Posts |
Posted - 2013-11-25 : 13:37:16
|
Thank you visakh16Will this command give me the current row number?For example, if i am current on line 2, will it give me "2" as the result of this query?And if possible, could you please explain "* from RDR1"?Thanks |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-11-25 : 13:40:50
|
quote: Originally posted by jane0829 Thank you visakh16Will this command give me the current row number?For example, if i am current on line 2, will it give me "2" as the result of this query?And if possible, could you please explain "* from RDR1"?Thanks
yep... it will based on your order (in this case by Quantity)* means select all other columnsfrom RDR1 means thats the table from which you want to fetch the data.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
jane0829
Starting Member
6 Posts |
Posted - 2013-11-25 : 13:47:24
|
Instead of a list of all the rows and columnsi will just need a row numberFor example, if i selected a field at line 4, and i run this query, it will give me a value of 4And if i selected a field at Line 10, it will give me a value of 10 as the query result.quote: Originally posted by visakh16
quote: Originally posted by jane0829 Thank you visakh16Will this command give me the current row number?For example, if i am current on line 2, will it give me "2" as the result of this query?And if possible, could you please explain "* from RDR1"?Thanks
yep... it will based on your order (in this case by Quantity)* means select all other columnsfrom RDR1 means thats the table from which you want to fetch the data.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs
|
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-11-25 : 14:16:12
|
if i selected a field at line 4, and i run this query, it will give me a value of 4And if i selected a field at Line 10, it will give me a value of 10 as the query result.what do you mean by Lane 4,Lane 10 etc? there's no concept of Lane or order in sql table unless you specify it by means of a order clause------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
jane0829
Starting Member
6 Posts |
Posted - 2013-11-25 : 14:35:24
|
I apologize for any confusion.I am currently working on SAP Business One and it is based on SQL DBIn my case, i have this Sales Order with 10 line items.In my query, i would like it to reflect the row number that i am currently on.For example, my field is $[$38.0.0.1]1 here means row 1instead of changing the row number each time when i switch to another row.I would like to use a query to identify the current row number automatically.quote: Originally posted by visakh16 if i selected a field at line 4, and i run this query, it will give me a value of 4And if i selected a field at Line 10, it will give me a value of 10 as the query result.what do you mean by Lane 4,Lane 10 etc? there's no concept of Lane or order in sql table unless you specify it by means of a order clause------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs
|
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2013-11-25 : 14:45:46
|
SQL deals with sets (generally), so there is no such thing a current row for a set. So you have some sample data you can provide that illustrates your issue and what you want the results to be? |
|
|
jane0829
Starting Member
6 Posts |
Posted - 2013-11-25 : 14:50:21
|
For example# Item Quantity Price1 A1 100 $12 A2 200 $2These two are the line items in my Sales OrderIf i am currently highlighting the quantity 200 in row 2I want to have a query, which will give me a result of 2, reflecting the row that i am currently on.quote: Originally posted by Lamprey SQL deals with sets (generally), so there is no such thing a current row for a set. So you have some sample data you can provide that illustrates your issue and what you want the results to be?
|
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2013-11-25 : 14:55:00
|
I'm still not understanding what you want. How is SQL Server supposed to know what row you have highlighted? |
|
|
jane0829
Starting Member
6 Posts |
Posted - 2013-11-25 : 15:00:05
|
Maybe i was wrong in the first placePlease let me figure it out first before further questionsThank you so muchquote: Originally posted by Lamprey I'm still not understanding what you want. How is SQL Server supposed to know what row you have highlighted?
|
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2013-11-25 : 15:03:26
|
quote: If i am currently highlighting the quantity 200 in row 2
this statement implies you are viewing this data in a front end application. The database can not know which row you have highlighted in the application. If you want to return this row from the underlying database then you need to pass in a row identifier. If people can write to this table while you are viewing it then a row_number() function may change between requests. Usually, because of that, the application will/should have a permanent row identifier along with this logical row. That would be the values of a primary key or unique constraint. Then your query would pass in that/those values to get that specific row.However, if the data is not likely to change between requests then you could say:declare @currentRow intset @currentRow = 2 --passed in valueselect <RDR1Columns>, @currentRowfrom ( SELECT <RDR1Columns>, [row] = ROW_NUMBER() OVER (ORDER BY QUANTITY) FROM RDR1 ) dWHERE d.[Row] = @CurrentRow But it would be better to pass in the permanent primary key value(s) (or other unique constraint value(s))Be One with the OptimizerTG |
|
|
|