Hello,
I would like to know if the equivalent Oracle rownum exist in
SQLServer. Here is a sample SQL code to explain what I want to do :
select
jobs.name,
jobs.job_id,
jobs.description,
hist.message,
hist.step_name,
hist.step_id,
hist.run_status,
hist.run_date,
hist.run_time,
hist.run_duration
from
msdb.dbo.sysjobs jobs,
msdb.dbo.sysjobhistory hist
where
jobs.job_id=hist.job_id
and hist.job_id='E71CCB97-81C3-46E2-83FA-BFFCB66B47F8'
order by
run_date, run_time
I just want the first or second row returned by this query. In Oracle I
can simply add rownum=1 or rownum=2 in the where clause to obtain the
desired answer. I don't know how to do in SQLServer.
Thank in advance,
Pierig. 4 18256
pierig.gueg...@gmail.com wrote: Hello,
I would like to know if the equivalent Oracle rownum exist in SQLServer. Here is a sample SQL code to explain what I want to do :
select jobs.name, jobs.job_id, jobs.description, hist.message, hist.step_name, hist.step_id, hist.run_status, hist.run_date, hist.run_time, hist.run_duration from msdb.dbo.sysjobs jobs, msdb.dbo.sysjobhistory hist where jobs.job_id=hist.job_id and hist.job_id='E71CCB97-81C3-46E2-83FA-BFFCB66B47F8' order by run_date, run_time
I just want the first or second row returned by this query. In Oracle
I can simply add rownum=1 or rownum=2 in the where clause to obtain the desired answer. I don't know how to do in SQLServer.
Thank in advance, Pierig.
Use the 'top n' clause
eg. select top 5
jobs.name,
jobs.job_id,
jobs.description,
hist.message, ...........
See TOP in Books Online:
select top 2 jobs.name, jobs.job_id, ...
Note that TOP doesn't take a variable, so if you need that flexibility,
you would need to use SET ROWCOUNT, which can use a variable.
Simon
You need to get a book on basic RDBMS design. Tables are sets, not
files. They have no ordering. The Oracle row numbers merely violate
Codd's rule #8 and tell us that under the covers, Oracle is a
sequential contigous file system. But it leads you contiue to create
file systems in SQL.
I see by the use of a GUID, another exposed physical locator, for a key
that you do not have a relational design at all. You also split date
and time into two columns than added a computed column called duration,
so you have NFNF problems.
You need to start over. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Syed Mudussir Husain |
last post by:
Hello,
I am doing a very large web based database project.
Over the period of 5 years, "more than 100, 000 Books" will be stored in a
Database along with a LARGE amount of book attributes...
|
by: dario.8282 |
last post by:
select pippo
from
(
select person.name as pippo
from person
)
This query run in oracle....in sqlserver no!
what can i do!?
thank's
|
by: jalicej |
last post by:
I have a trigger in oracle. I need to convert it into SQL server. Can anyone help me. This is the trigger to be converted.
CREATE OR REPLACE TRIGGER TR_MYTRIGGER AFTER UPDATE ON TB_USER
FOR EACH...
|
by: pnalla |
last post by:
Hi,
provide the connection string for mySql,oracle,Db2,sqlserver uisng C#
please provide the code for above databses
Thanks
Prasad
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
| |