Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6245823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:34:36+00:00 2026-05-24T12:34:36+00:00

I am connecting to an SQL database using a PLC, and need to return

  • 0

I am connecting to an SQL database using a PLC, and need to return a list of values. Unfortunately, the PLC has limited memory, and can only retrieve approximately 5,000 values at any one time, however the database may contain up to 10,000 values.

As such I need a way of retrieving these values in 2 operations. Unfortunately the PLC is limited in the query it can perform, and is limited to only SELECT and WHERE commands, so I cannot use LIMIT or TOP or anything like that.

Is there a way in which I can create a view, and auto number every field in that view? I could then query all records < 5,000, followed by a second query of < 10,000 etc?

Unfortunately it seems that views do not support the identity column, so this would need to be done manually.

Anyone any suggestions? My only realistic option at the moment seems to be to create 2 views, one with the first 5,000 and 1 with the next 5,000…

I am using SQL Server 2000 if that makes a difference…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T12:34:38+00:00Added an answer on May 24, 2026 at 12:34 pm

    While the code provided by Derek does what I asked – i.e numbers each row in the view, the performance for this is really poor – approximately 20 seconds to number 100 rows. As such it is not a workable solution. An alternative is to number the first 5,000 records with a 1, and the next 5,000 with a 2. This can be done with 3 simple queries, and is far quicker to execute.

    The code to do so is as follows:

    SELECT TOP(5000) BCode, SAPCode, 1 as GroupNo FROM dbo.DB 
    UNION
    SELECT TOP (10000) BCode, SAPCode, 2 as GroupNo FROM dbo.DB p 
    WHERE ID NOT IN (SELECT TOP(5000) ID FROM dbo.DB)
    

    Although, as pointed out by Andriy M, you should also specify an explicit sort, to ensure the you dont miss any records.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having difficulty connecting my java code to sql server database. I can
I am (successfully) connecting to a database using the following: java.sql.Connection connect = DriverManager.getConnection(
hi i want to retrieve values from SQL database for xml tags using java
I built a .NET ASMX web service connecting to an SQL Server database. There
i want to practice connecting from asp.net to a sql server database. i have
Currently we have a hybrid ASP/PHP setup connecting to a SQL Server 2005 database.
We have a SQL Server 2005 database, and currently all our users are connecting
I need to make a connection to a Sybase (SQL Anywhere) database in a
I'm connecting to a MySQL database using the MySqlClient class. When I try to
Using SQL 2000, SQL 2005 Old Database Name is – Sysdatabase New Database Name

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.