.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan
Asad Ali
Post New Web Links

Select top 100 rows from n row

Posted By:      Posted Date: September 21, 2010    Points: 0   Category :Sql Server
 

Hi! I need to select top rows, for example, from 100 to 200! For that I am using this code:

select * from doc as a where (select count(*) from doc as b where b.idn <= a.idn) between 100 and 200
 But this is working to slow is there another way to do this. Thanks!




View Complete Post


More Related Resource Links

Delete objects from table using another table to select rows - help needed

  
I have one table named 'dbo.ac_Products'Within this table there is a column named 'ProductId'There is also another table named 'dbo.ac_CatalogNodes'Within this table there is a column named 'CatalogNodeId'and a column named 'CatalogNodeType'I need to delete all the rows from 'dbo.ac_Products' and 'dbo.ac_CatalogNodes' where 'ProductId' = 'CatalogNodeId' and 'CatalogNodeType' = 1Any help would be greatly appreciated!

Conditional insert: If select return rows, insert rows to table otherwise insert specific row indica

  
This is what I have

Insert into ReportDetail( Partcipantid, Reportid)  

select distinct ParticipantID , 9 from OpenCredit

      except select ParticipantID, 9 from StoreCredit where Closed = 0

 Issue is that when above select statement returns no row, it seems like no record is

Select second query if first query returns no rows

  

Hi

I need to return result of the second select statement if the first select statement returns nothing:

-- First statement
SELECT Salesmen.SalesmanID, Salesmen.FullName, 
  Salesmen.AssignedAppointments, Salesmen.Picture, 
  Appointments.Closed
FROM Appointments INNER JOIN
  Salesmen ON 
  Appointments.SalesmanID = Salesmen.SalesmanID
WHERE (Appointments.Closed = 1)
ORDER BY Salesmen.AssignedAppointments
-- Second statement
SELECT *
FROM Salesmen
ORDER BY AssignedAppointments


Select Primary Key Column of Table returns 0 rows

  

I have three tables: Design, Box, Wall.

Design has a column DesignId that is a GUID. It does not allow nulls, is unique, and is the primary key. The identity is set to false for compatibility with Entity Framework v4.

Box has  a column BoxId that is a GUID. It does not allow nulls, is unique, and is the primary key. The identity is set to false as well.

Box also has a column DesignId that is a GUID. It does not allow nulls, is not unique and is not the primary key.

Wall has  a column WallId that is a GUID. It does not allow nulls, is unique, and is the primary key. The identity is set to false as well.

Wall also has a column DesignId that is a GUID. It does not allow nulls, is not unique and is not the primary key.

Wall also has a column BoxId that is a GUID. It does not allow nulls, is not unique and is not the primary key.

Box.DesignId has been set as a ForeignKey relating to Design.DesignId.

Wall.DesignId has been set as a ForeignKey relating to Design.DesignId

Wall.BoxId has been set as a ForeignKey relating to Box.BoxId.

 

If I execute      SELECT DesignId FROM Design     I see the correct number of rows.

If I execute     SELECT BoxId From Box        I see zer

How to select all rows in grid from a click event?

  

Hello,

I'm using the code below to select multiple rows in a gridview using a checkbox, how do I modify the code in a "select all" button click event to select all the rows by checking the checkboxes in all the rows? How do I also clear all the checkboxes using sa "Clear" button click event?

<asp:GridView ID="GridView2" runat="server" Height="211px" Width="16px">

<Columns>

<asp:TemplateField HeaderText="SomeText" >

<ItemTemplate>

<asp:CheckBox ID="CheckBox1" runat="server" Text="" />

</ItemTemplate>

</asp:TemplateField>

</Columns>

</asp:GridView>

Thank You.

Victor 


select random if multiple rows are the same?

  

Hi,

i have a select statement which returns a column value.

id like to display the lowest column value there is, but if there are multiple rows with the same (and lowest) value id like it to be random which one of the rows is selected.. how would i do this? my select statement is currently:

SELECT     TOP (1) url, ABS(r1 - @r1) + ABS(r2 - @r2)  AS difference
FROM         type
ORDER BY difference

this picks the one lowest result for me, but if there are multiple duplicate lowest results id like to select them, and show one at random..?


SQL Server Linked Server -IBMDASQL SQL select statement does not show rows

  

Exec ('SELECT * FROM filename') at TST_IBMDASQL

The above SQL statement using Linked Server IBMDASQL, does not show rows it only show the following message:
(1 row(s) affected)

And then if I run the statement, Exec ('SELECT * FROM filename') at TST_IBMDASQL, twice quickly i get the above message then on the second
run i get the message:

OLE DB provider "IBMDASQL" for linked server "TST_IBMDASQL" returned message "SQL0519: Prepared statement S000001 in use.
Cause . . . . . : The application program has attempted to prepare statement S000001. This statement is the SELECT statement for cursor C000001 that is currently open. Recovery . . . : Change the statement name in the PREPARE statement or correct the logic of the application program so that it closes cursor C000001 before attempting the PREPARE statement again.".
Msg 7215, Level 17, State 1, Line 1
Could not execute statement on remote server 'TST_IBMDASQL'.



Its like the whole statement is running on the remote and not returning anything other than the message "(1 row(s) affected)"

This has been working great for years until I formatted the computed and reinstalled everything. Its also working fine on the laptop and at work
and i've compared all settings - all looks ok.

There mus

Select all rows from one checkbox in a GridView

  
The article Select all rows from one checkbox in a GridView was added by tmorton on Thursday, May 12, 2011.

Today i'm going to show you how to select all records in a gridview from one checkbox which located in gridview header.First set gridview like below code snnippetasp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"

How to perform insert, update, delete and select rows in ASP.NET gridview control using stored proce

  
In this article, we will explore how to add, update, delete and select a record from sql server database using gridview control in a simple way. I'm using visual studio 2010 and sql server 2008 for this sample.

Gridview header checkbox select and deselect all rows using client side JavaScript and server sideC#

  
In this article, I will show you how to add checkbox in gridview header template then select and deselect all rows in gridview using clients side JavaScript and server side as well.

Adding Dynamic Rows in ASP.NET GridView Control with TextBoxes and with Delete functionality

  
In my previous examples, I have demonstrated on how to add dynamic rows in GridView control with TextBoxes and how to save the values into the database. Now, seems that most of the developers are asking if how to add a delete functionality with it. So in this example, I'm going to show on how to delete a certain row in the dynamic GridView with TextBoxes.

AJAX GridView Checkbox Select All in ASP.Net

  
In the previous article GridView Select Multiple Rows you learnt the multiple row selection in GridView control. Here you will get the C# code sample to select all the gridview rows using single checkbox server control. You can highlight the selected rows with different color and Font state Bold. If you want to use the selection values on different ASP.Net

jQuery: Highlight Gridview Rows with Checkbox

  
Im learning and experimenting with jQuery and ASP.NET. Below is a simple solution I created to highlight rows in a gridview by clicking on a checkbox next to the row.

Gridview setup:

Highlighting Rows with TextBox OnFocus

  
In another article I explained that how you can make the rows of the GridView control clickable and highlight them when they are clicked. In this article I will explain that how you can highlight the GridView rows when you focus on the TextBox which is contained inside the GridView control.

jQuery: Highlight Gridview Rows with Checkbox

  
Im learning and experimenting with jQuery and ASP.NET. Below is a simple solution I created to highlight rows in a gridview by clicking on a checkbox next to the row.

jQuery: Styling DropDownList Alternating Items (Rows)

  
In the following example, I will show how you can style any asp:dropdownlist very easily.

The example demonstrates how you can change alternating row items background color, using the fadeTo() to add a nice touch in the dropdownlist. You can change alt rows with a couple lines.

MS SQL Server: Search All Tables, Columns & Rows For Data or Keyword Query

  
If you need to search your entire database for specific data, this query will come in handy.

So when a client needs a custom report or some sort of custom development using Great Plains, most of the time I will have to track down the data in the system by running this query and find the table(s) it is in.
Categories: 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend