PDA

View Full Version : خواندن به تعداد دلخواه اطلاعات از بانک اطلاعاتی



روح اله معینی زاده
یک شنبه 08 آبان 1384, 13:32 عصر
سلام خدمت دوستان گرامی

چه جوری می شه مثلاً 100 رکورد 100 رکورد از بانک اطلاعاتی داده‌ها رو بازیابی کرد؟ یعنی 100 تای اول رو که خوند، با زدن یک کلید 100 تای بعدی رو بخونه و همین طور تا انتها.

با احترام- خدانگهدار

habedijoo
یک شنبه 08 آبان 1384, 13:42 عصر
سلام

برای این کار باید از کرسر (Cursor ) استفاده کنی .

روح اله معینی زاده
یک شنبه 08 آبان 1384, 13:56 عصر
سلام مجدد

خب چطوری؟

با احترام- خدانگهدار

رضا دریایی
دوشنبه 09 آبان 1384, 16:35 عصر
سلام دوست من
اول تعداد رکردها رو بدست بیار وبعد با یه دستور ساده اس کیو ال درصد مورد نظرت رو از رکردها بردار

موفق باشید

رضا دریایی
دوشنبه 09 آبان 1384, 16:37 عصر
سلام دوست من
اول تعداد رکوردها رو بدست بیار وبعد با یه دستور ساده اس کیو ال درصد مورد نظرت رو از رکردها بردار

موفق باشید

sinpin
دوشنبه 09 آبان 1384, 20:48 عصر
Dim dap As SqlClient.SqlDataAdapter
dap.Fill(dst, startRecord, maxRecord, Table)

Hamedm
دوشنبه 09 آبان 1384, 22:32 عصر
سلام

برای این کار باید از کرسر (Cursor ) استفاده کنی .

سلام

ای بابا چرا الکی مسئله رو پیچیده میکنید. در SELECT از TOP n استفاده کن. همین...
البته میشه هم از کرسر استفاده کرد و هم DataSet رو Fill کرد و 100 تا 100 تا نشون داد، اما اینجوری ممکنه در شبکه بین دیدن 100تای اول تا دوم فاصله زیادی بیفته و اطلاعات بروز به کاربر نشون داده نشه.
از همون TOP n در SELECT استفاده کن تا دیگه به این مشکلات بر نخوری.

در پناه حق موفق باشید و پرتوان

روح اله معینی زاده
چهارشنبه 11 آبان 1384, 06:56 صبح
سلام
آقا حامد می شه یه نمونه بنویسید. من تا حالا از Top استفاده نکردم و نمی دونم چه طوری نوشته می شه و ... .
با احترام- خدانگهدار

Hamedm
چهارشنبه 11 آبان 1384, 21:53 عصر
سلام
آقا حامد می شه یه نمونه بنویسید. من تا حالا از Top استفاده نکردم و نمی دونم چه طوری نوشته می شه و ... .
با احترام- خدانگهدار

سلام

اگه به توضیحات بیشتری نیاز داشتی بگو تا برات بدم.

Syntax

SELECT [ ALL | DISTINCT ]
[ TOP n [ PERCENT ] [ WITH TIES ] ]
< select_list >

< select_list > ::=

{ *
| { table_name | view_name | table_alias }.*
| { column_name | expression | IDENTITYCOL | ROWGUIDCOL }
[ [ AS ] column_alias ] | column_alias = expression
} [ ,...n ]

Arguments

ALL

Specifies that duplicate rows can appear in the result set. ALL is the default.

DISTINCT

Specifies that only unique rows can appear in the result set. Null values are considered equal for the purposes of the DISTINCT keyword.

TOP n [PERCENT]

Specifies that only the first n rows are to be output from the query result set. n is an integer between 0 and 4294967295. If PERCENT is also specified, only the first n percent of the rows are output from the result set. When specified with PERCENT, n must be an integer between 0 and 100.

If the query includes an ORDER BY clause, the first n rows (or n percent of rows) ordered by the ORDER BY clause are output. If the query has no ORDER BY clause, the order of the rows is arbitrary.

WITH TIES

Specifies that additional rows be returned from the base result set with the same value in the ORDER BY columns appearing as the last of the TOP n (PERCENT) rows. TOP ...WITH TIES can only be specified if an ORDER BY clause is specified.

< select_list >

The columns to be selected for the result set. The select list is a series of expressions separated by commas.

* Specifies that all columns from all tables and views in the FROM clause should be returned. The columns are returned by table or view, as specified in the FROM clause, and in the order in which they exist in the table or view.
table_name | view_name | table_alias.* Limits the scope of the * to the specified table or view.
column_name Is the name of a column to return.Qualify column_name to prevent an ambiguous reference, such as occurs when two tables in the FROM clause have columns with duplicate names. For example, the Customers and Orders tables in the Northwind database both have a column named ColumnID. If the two tables are joined in a query, the customer ID can be specified in the select list as Customers.CustomerID.
expression Is a column name, constant, function, any combination of column names, constants, and functions connected by an operator(s), or a subquery.
IDENTITYCOL Returns the identity column. For more information, see IDENTITY (Property) (ts_ia-iz_3iex.htm), ALTER TABLE (ts_aa-az_3ied.htm), and CREATE TABLE (ts_create2_8g9x.htm). If the more than one table in the FROM clause has a column with the IDENTITY property, IDENTITYCOL must be qualified with the specific table name, such as T1.IDENTITYCOL.


ROWGUIDCOL Returns the row global unique identifier column. If the more than one table in the FROM clause with the ROWGUIDCOL property, ROWGUIDCOL must be qualified with the specific table name, such as T1.ROWGUIDCOL.


column_alias Is an alternative name to replace the column name in the query result set. For example, an alias such as "Quantity", or "Quantity to Date", or "Qty" can be specified for a column named quantity. Aliases are used also to specify names for the results of expressions, for example:

USE Northwind
SELECT AVG(UnitPrice) AS 'Average Price'
FROM [Order Details]
column_alias can be used in an ORDER BY clause. However, it cannot be used in a WHERE, GROUP BY, or HAVING clause. If the query expression is part of a DECLARE CURSOR statement, column_alias cannot be used in the FOR UPDATE clause.

INTO Clause

Creates a new table and inserts the resulting rows from the query into it.

The user executing a SELECT statement with the INTO clause must have CREATE TABLE permission in the destination database. SELECT...INTO cannot be used with the COMPUTE. For more information, see Transactions (javascript:hhobj_1.Click()) and Explicit Transactions (javascript:hhobj_2.Click()).

You can use SELECT...INTO to create an identical table definition (different table name) with no data by having a FALSE condition in the WHEREclause.

Syntax

[ INTO new_table ]

Arguments

new_table

Specifies the name of a new table to be created, based on the columns in the select list and the rows chosen by the WHERE clause. The format of new_table is determined by evaluating the expressions in the select list. The columns in new_table are created in the order specified by the select list. Each column in new_table has the same name, data type, and value as the corresponding expression in the select list.

When a computed column is included in the select list, the corresponding column in the new table is not a computed column. The values in the new column are the values that were computed at the time SELECT...INTO was executed.

In this release of SQL Server, the select into/bulkcopy database option has no effect on whether you can create a permanent table with SELECT INTO. The amount of logging for certain bulk operations, including SELECT INTO, depends on the recovery model in effect for the database. For more information, see Using Recovery Models (javascript:hhobj_3.Click()).

In previous releases, creating a permanent table with SELECT INTO was allowed only if select into/bulkcopy was set.

select into/bulkcopy is available for backward compatibility purposes, but may not be supported in future releases. Refer to the Recovery Models and Backward Compatibility and



برای Query هم که شما مد نظرتونه بای دوتا SELECT تو در تو بنویسید.

در پناه حق موفق باشید و پرتوان

روح اله معینی زاده
پنج شنبه 12 آبان 1384, 10:16 صبح
سلام حامد آقا

درست، ولی نوشتم و جواب نداد. اگه یه نمونه دستورش رو بنویسید متشکر می شم.

با احترام- خدانگهدار

Hamedm
پنج شنبه 12 آبان 1384, 22:45 عصر
سلام حامد آقا

درست، ولی نوشتم و جواب نداد. اگه یه نمونه دستورش رو بنویسید متشکر می شم.

با احترام- خدانگهدار

سلام

ببین همون طور که گفتم نیاز به SELECT تو در تو داری.

مثلا ما میخواهیم رکوردهای 100 تا 200 رو لیست کنید، با این صورت عمل میکنید:
اول با یک SELECT TOP 200 میایم 200های ابتدایی رو بصورت نزولی لیست میکنیم بعد از این لیست بدست اومده 100تای ابتدایی رو بصورت صعودی لیست میکنیم. لیست دوم بدست اومده حاوی رکوردهای 100 تا 200 است.

البته اگه رکوردهاتو نمیخواهی مرتب شده نشون بدی، نیازی نیست صعودی یا نزولی کنی.


در پناه حق موفق باشید و پرتوان

روح اله معینی زاده
جمعه 13 آبان 1384, 23:53 عصر
سلام آقا حامد

برو سر اصل مطلب. چرا SELECT رو نمی نویسی؟ یعنی مثلا من این جوری بنویسم


select top 200 from x


پس تو دستور چه طوری فیلدهای لازمه رو مشخص کنم؟

امیدوارم متوجه شده باشید منظور من از نمونه‌ای که خواسته بودم، چیه؟!

با احترام- خدانگهدار

Hamedm
شنبه 14 آبان 1384, 00:12 صبح
سلام آقا حامد

برو سر اصل مطلب. چرا SELECT رو نمی نویسی؟ یعنی مثلا من این جوری بنویسم


select top 200 from x


پس تو دستور چه طوری فیلدهای لازمه رو مشخص کنم؟

امیدوارم متوجه شده باشید منظور من از نمونه‌ای که خواسته بودم، چیه؟!

با احترام- خدانگهدار

سلام

به SELECT زیر توجه کنید:


SELECT TOP T1 * FROM (SELECT TOP T2 * FROM TableName) AS VT ORDER BY FieldName DESC

T1 مقدار حد پایین و T2 مقدار حد بالا است.


در پناه حق موفق باشید و پرتوان