View Full Version : سوال: یک دستور select
mina.net
شنبه 19 اردیبهشت 1388, 09:34 صبح
سلام دوستان
من می خوام مانده بدهکار و بستانکار یک جدول حسابداری (دفتر کل) رو به دست بیارم البته به ترتیب تاریخ یعنی در هر سطری مانده تا این سطر را مشخص کنه و اگر منفی بود مقدار رو صفر بزنه.
mk1984
شنبه 19 اردیبهشت 1388, 12:01 عصر
واسه select میتونی بر اساس تاریخ Group By انجام بدی
[SELECT SUM(Bedehkar),SUM(Bestankar),[Date] FROM [TableName] GROUP BY [Date
برای صفر کردن مقدار منفی هم این رو به ادامه SELECT اضافه کن
ISNULL(NULLIF(ABS(SUM(Bedehkar)-SUM(Bestankar))*-1,(SUM(Bedehkar)-SUM(Bestankar))),0)
حمیدرضاصادقیان
شنبه 19 اردیبهشت 1388, 14:17 عصر
سلام.اگر جستجو کنید خیلی سریعتر به نتیجه خواهید رسید.
mina.net
شنبه 19 اردیبهشت 1388, 14:38 عصر
سلام دوستان
من می خوام همه رکورد های قبلی در هر سطر مانده بدهکار یا بستانکار را تا اون تاریخ رو نشون بده و همین طور سطرهای بعدی یعنی هر سطری براساس تاریخ قبلی مشخص کنه.
mina.net
سه شنبه 22 اردیبهشت 1388, 20:34 عصر
شاید من درست توضیح ندادم من می خوام برای فرضا یک شخص مانده بد و بست رو براساس تاریخ بگیرم یک فایل ورد حاوی یک جدول در زیر قرار دادم شاید بتونه منظورم رو بهتر برسونه.
mina.net
پنج شنبه 24 اردیبهشت 1388, 14:58 عصر
دوستان لطفا کمک کنید خیلی گیر این برنامه هستم.
amin_alexi
پنج شنبه 24 اردیبهشت 1388, 21:04 عصر
سلام
این موضوع تو سایت زیاد در موردش بحث شده (Running Total Value) در Google هم با این Search بزنی زیاد پیدا میکنی !
این چند لینک رو هم ببین خیلی کمکت میکنه !
http://barnamenevis.org/forum/showthread.php?t=138784
http://www.databasejournal.com/features/mssql/article.php/3112381/SQL-Server-Calculating-Running-Totals-Subtotals-and-Grand-Total-Without-a-Cursor.htm
امید وارم کمکت کنه !
Hamid.Mayeli
جمعه 25 اردیبهشت 1388, 11:51 صبح
دوست عزيز دو SQL دنبالش نگرد تو Report بايد درستش كني مثلا Crystal Report اين كار توش مثل آب خوردنه.
اگه با Crystal كار مي كني بگم چيكار كن.
Hamid.Mayeli
جمعه 25 اردیبهشت 1388, 12:01 عصر
سلام
این موضوع تو سایت زیاد در موردش بحث شده (Running Total Value) در Google هم با این Search بزنی زیاد پیدا میکنی !
این چند لینک رو هم ببین خیلی کمکت میکنه !
http://barnamenevis.org/forum/showthread.php?t=138784
http://www.databasejournal.com/features/mssql/article.php/3112381/SQL-Server-Calculating-Running-Totals-Subtotals-and-Grand-Total-Without-a-Cursor.htm
امید وارم کمکت کنه !
اين راه حل تو لينك بالا بود.
select OrderId, OrderDate, O.OrderAmt ,(select sum(OrderAmt) from Orders where OrderID <= O.OrderID) 'Running Total'from Orders Oكه من اصلا تاييد نمي كنم هرچند جواب ميده ولي خيلي كند مي كنه.تو Report خيلي سريعتر انجام ميشه.
mina.net
جمعه 25 اردیبهشت 1388, 14:20 عصر
سلام دوستان
من با کدی که در لینکی که جناب amin_alexi گذاشتن بود کد زیر رو نوشتم و جواب هم داد منتها یک عیب وجود دارد . از اونجای که ایدی به ترتیب تاریخ نیست و برای کاربر من تاریخ براش مهمه پس من شرط رو تاریخ گذاشتم. تا اینجا خوب کار می کنه ولی وقتی تو یک تاریخ دو تا سند به نام یک نفر صادر شده باشه اونوقت هر دو سطر مقدار برابر خواهند داشت. دوستان برای حل این مشکل چه پیشنهدی دارید.
select mainid,sharh,BED,BEST,tarikh,(select case when (sum(bed)-sum(best))<0 then '0' else (sum(bed)-sum(best))end from bed_best where tarikh <t1.tarikh+1 and id ='51' ) as mbed,(select case when (sum(best)-sum(bed))<0 then '0' else (sum(best)-sum(bed))end from bed_best where tarikh <t1.tarikh+1 and id ='51' ) as mbest from bed_best t1 where id = '51' order by tarikh
توضیح
mainid از نوع bigiant
sharh از نوع nvarchar
bed , best از نوع number هستند که در حقیقت همون ستون بدهکار و بستانکار من هستند.
tarikh از نوع nvarcharchar هست.
خوب من مانده بدهکار و مانده بستانکار رو تا tarikh< tarikh+1 حساب می کنم. که البته مشکل همین جا هست که اگر در یک روز دو سند یا بیشتر به نام یک حساب صادر بشه مقدار هر دو رو یکی نشون می ده.
عدد 51 نمونه هست در حقیقت ایدی حسابی رو که می خواهیم ازش گزارش بگیریم اینجا می زاریم.
mina.net
جمعه 25 اردیبهشت 1388, 14:28 عصر
دوست عزيز دو SQL دنبالش نگرد تو Report بايد درستش كني مثلا Crystal Report اين كار توش مثل آب خوردنه.
اگه با Crystal كار مي كني بگم چيكار كن.
دوست عزیز سلام
بگید ما منتظر راهنمود های شما هستیم.
amin_alexi
شنبه 26 اردیبهشت 1388, 01:08 صبح
اين راه حل تو لينك بالا بود.
select OrderId, OrderDate, O.OrderAmt ,(select sum(OrderAmt) from Orders where OrderID <= O.OrderID) 'Running Total'from Orders Oكه من اصلا تاييد نمي كنم هرچند جواب ميده ولي خيلي كند مي كنه.تو Report خيلي سريعتر انجام ميشهاگه لینک اول رو تا آخر می خوندی میدیدی که یک راه حل دیگه هم ارائه شده و من منظورم همون راه حل دوم بود حتی من در اونجا خودم هم دو روش رو با زمان مقایسه کردم ... و گفتم که روش استفاده از Cursor سریعتره .... :چشمک:
سلام دوستان
من با کدی که در لینکی که جناب amin_alexi گذاشتن بود کد زیر رو نوشتم و جواب هم داد منتها یک عیب وجود دارد . از اونجای که ایدی به ترتیب تاریخ نیست و برای کاربر من تاریخ براش مهمه پس من شرط رو تاریخ گذاشتم. تا اینجا خوب کار می کنه ولی وقتی تو یک تاریخ دو تا سند به نام یک نفر صادر شده باشه اونوقت هر دو سطر مقدار برابر خواهند داشت. دوستان برای حل این مشکل چه پیشنهدی دارید.
کد:
select mainid,sharh,BED,BEST,tarikh,(select case when (sum(bed)-sum(best))<0 then '0' else (sum(bed)-sum(best))end from bed_best where tarikh <t1.tarikh+1 and id ='51' ) as mbed,(select case when (sum(best)-sum(bed))<0 then '0' else (sum(best)-sum(bed))end from bed_best where tarikh <t1.tarikh+1 and id ='51' ) as mbest from bed_best t1 where id = '51' order by tarikh
توضیح
mainid از نوع bigiant
sharh از نوع nvarchar
bed , best از نوع number هستند که در حقیقت همون ستون بدهکار و بستانکار من هستند.
tarikh از نوع nvarcharchar هست.
خوب من مانده بدهکار و مانده بستانکار رو تا tarikh< tarikh+1 حساب می کنم. که البته مشکل همین جا هست که اگر در یک روز دو سند یا بیشتر به نام یک حساب صادر بشه مقدار هر دو رو یکی نشون می ده.
عدد 51 نمونه هست در حقیقت ایدی حسابی رو که می خواهیم ازش گزارش بگیریم اینجا می زاریم. شما یک فیلد به این Query اضافه کن یا یک View بساز که یک فیلد به عنوان ترتیب داشته باشی اسمشو بزار مثلا ID و به جای tarikh< tarikh+1 از اون ID استفاده کن
و بهتر اینه که از Cursor استفاده کنی مثال تو لینک اول هست
موفق باشی !:چشمک:
Hamid.Mayeli
شنبه 26 اردیبهشت 1388, 10:22 صبح
اگه لینک اول رو تا آخر می خوندی میدیدی که یک راه حل دیگه هم ارائه شده و من منظورم همون راه حل دوم بود حتی من در اونجا خودم هم دو روش رو با زمان مقایسه کردم ... و گفتم که روش استفاده از Cursor سریعتره .... :چشمک:بله شايد Cursor بهتر از Sum باشه وليWhile از Cursor بهتره و باز خيلي كندتر از Report Generator كار ميكنه اگه از Cursorاستفاده ميكني Forward_Only & Read_Only & ... رو فراموش نكن كه شايد تندتر كار كنه.
شما یک فیلد به این Query اضافه کن یا یک View بساز که یک فیلد به عنوان ترتیب داشته باشی اسمشو بزار مثلا ID و به جای tarikh< tarikh+1 از اون ID استفاده کن
از View سعي كن كلا استفاده نكني كه باز كندتر ميشه.
بگرد دنبال مباحث Data Where Housing يا يه همچين چيزي. به منم نتيجه رو بگيد ممنون ميشم.
mina.net
شنبه 26 اردیبهشت 1388, 14:25 عصر
و بهتر اینه که از Cursor استفاده کنی مثال تو لینک اول هست
سلام دوست عزیز من خیلی راجع به SQL نمی دونم اگه می شه بیشتر توضیح بدید چطور می تونم یک Cursor بسازم و ازش استفاده کنم یا حداقل یک لینکی که راجع به این موضوع مفصلا بحث کرده معرفی نمایید ممنون می شم.
از View سعي كن كلا استفاده نكني كه باز كندتر ميشه.
بگرد دنبال مباحث Data Where Housing يا يه همچين چيزي. به منم نتيجه رو بگيد ممنون ميشم.
دوست عزیز من می خوام گزارش رو برای تفضیلی ها بگیرم شاید اونی که خیلی روکوردش زیاد هست به 1000 برسه بنظرت خیلی کند می شه.در ضمن Data Where Housing اصلا چی هست یک توضیح مقدماتی بفرمایید تا من بتونم بیشتر تحقیق کنم.
بازم ممنون از همکاری که دارید امیدوارم با کمک هم این موضوع رو به کلی حل کنیم.
Hamid.Mayeli
شنبه 26 اردیبهشت 1388, 15:08 عصر
Declare Cursor CurName For
Select ColName From tableName
Open CurName
Fetch Next From CurName Into @ColName
While @@Fetch_Status = 0
Begin
Fetch Next From CurName Into @ColName
End
Close CurName
Deallocate CurName
DECLARE CURSOR
Defines the attributes of a Transact-SQL server cursor, such as its scrolling behavior and the query used to build the result set on which the cursor operates. DECLARE CURSOR accepts both a syntax based on the SQL-92 standard and a syntax using a set of Transact-SQL extensions.
SQL-92 Syntax
DECLARE cursor_name [ INSENSITIVE ] [ SCROLL ] CURSOR
FOR select_statement
[ FOR { READ ONLY | UPDATE [ OF column_name [ ,...n ] ] } ]
Transact-SQL Extended Syntax
DECLARE cursor_name CURSOR
[ LOCAL | GLOBAL ]
[ FORWARD_ONLY | SCROLL ]
[ STATIC | KEYSET | DYNAMIC | FAST_FORWARD ]
[ READ_ONLY | SCROLL_LOCKS | OPTIMISTIC ]
[ TYPE_WARNING ]
FOR select_statement
[ FOR UPDATE [ OF column_name [ ,...n ] ] ]
SQL-92 Arguments
cursor_name
Is the name of the Transact-SQL server cursor defined. cursor_name must conform to the rules for identifiers. For more information about rules for identifiers, see Using Identifiers.
INSENSITIVE
Defines a cursor that makes a temporary copy of the data to be used by the cursor. All requests to the cursor are answered from this temporary table in tempdb; therefore, modifications made to base tables are not reflected in the data returned by fetches made to this cursor, and this cursor does not allow modifications. When SQL-92 syntax is used, if INSENSITIVE is omitted, committed deletes and updates made to the underlying tables (by any user) are reflected in subsequent fetches.
SCROLL
Specifies that all fetch options (FIRST, LAST, PRIOR, NEXT, RELATIVE, ABSOLUTE) are available. If SCROLL is not specified in an SQL-92 DECLARE CURSOR, NEXT is the only fetch option supported. SCROLL cannot be specified if FAST_FORWARD is also specified.
select_statement
Is a standard SELECT statement that defines the result set of the cursor. The keywords COMPUTE, COMPUTE BY, FOR BROWSE, and INTO are not allowed within select_statement of a cursor declaration.
Microsoft® SQL Server™ implicitly converts the cursor to another type if clauses in select_statement conflict with the functionality of the requested cursor type. For more information, see Implicit Cursor Conversions.
READ ONLY
Prevents updates made through this cursor. The cursor cannot be referenced in a WHERE CURRENT OF clause in an UPDATE or DELETE statement. This option overrides the default capability of a cursor to be updated.
UPDATE [OF column_name [,...n]]
Defines updatable columns within the cursor. If OF column_name [,...n] is specified, only the columns listed allow modifications. If UPDATE is specified without a column list, all columns can be updated.
Transact-SQL Extended Arguments
cursor_name
Is the name of the Transact-SQL server cursor defined. cursor_name must conform to the rules for identifiers. For more information about rules for identifiers, see Using Identifiers.
LOCAL
Specifies that the scope of the cursor is local to the batch, stored procedure, or trigger in which the cursor was created. The cursor name is only valid within this scope. The cursor can be referenced by local cursor variables in the batch, stored procedure, or trigger, or a stored procedure OUTPUT parameter. An OUTPUT parameter is used to pass the local cursor back to the calling batch, stored procedure, or trigger, which can assign the parameter to a cursor variable to reference the cursor after the stored procedure terminates. The cursor is implicitly deallocated when the batch, stored procedure, or trigger terminates, unless the cursor was passed back in an OUTPUT parameter. If it is passed back in an OUTPUT parameter, the cursor is deallocated when the last variable referencing it is deallocated or goes out of scope.
GLOBAL
Specifies that the scope of the cursor is global to the connection. The cursor name can be referenced in any stored procedure or batch executed by the connection. The cursor is only implicitly deallocated at disconnect.
Note If neither GLOBAL or LOCAL is specified, the default is controlled by the setting of the default to local cursor database option. In SQL Server version 7.0, this option defaults to FALSE to match earlier versions of SQL Server, in which all cursors were global. The default of this option may change in future versions of SQL Server. For more information, see Setting Database Options.
FORWARD_ONLY
Specifies that the cursor can only be scrolled from the first to the last row. FETCH NEXT is the only supported fetch option. If FORWARD_ONLY is specified without the STATIC, KEYSET, or DYNAMIC keywords, the cursor operates as a DYNAMIC cursor. When neither FORWARD_ONLY nor SCROLL is specified, FORWARD_ONLY is the default, unless the keywords STATIC, KEYSET, or DYNAMIC are specified. STATIC, KEYSET, and DYNAMIC cursors default to SCROLL. Unlike database APIs such as ODBC and ADO, FORWARD_ONLY is supported with STATIC, KEYSET, and DYNAMIC Transact-SQL cursors. FAST_FORWARD and FORWARD_ONLY are mutually exclusive; if one is specified the other cannot be specified.
STATIC
Defines a cursor that makes a temporary copy of the data to be used by the cursor. All requests to the cursor are answered from this temporary table in tempdb; therefore, modifications made to base tables are not reflected in the data returned by fetches made to this cursor, and this cursor does not allow modifications.
KEYSET
Specifies that the membership and order of rows in the cursor are fixed when the cursor is opened. The set of keys that uniquely identify the rows is built into a table in tempdb known as the keyset. Changes to nonkey values in the base tables, either made by the cursor owner or committed by other users, are visible as the owner scrolls around the cursor. Inserts made by other users are not visible (inserts cannot be made through a Transact-SQL server cursor). If a row is deleted, an attempt to fetch the row returns an @@FETCH_STATUS of -2. Updates of key values from outside the cursor resemble a delete of the old row followed by an insert of the new row. The row with the new values is not visible, and attempts to fetch the row with the old values return an @@FETCH_STATUS of -2. The new values are visible if the update is done through the cursor by specifying the WHERE CURRENT OF clause.
DYNAMIC
Defines a cursor that reflects all data changes made to the rows in its result set as you scroll around the cursor. The data values, order, and membership of the rows can change on each fetch. The ABSOLUTE fetch option is not supported with dynamic cursors.
FAST_FORWARD
Specifies a FORWARD_ONLY, READ_ONLY cursor with performance optimizations enabled. FAST_FORWARD cannot be specified if SCROLL or FOR_UPDATE is also specified. FAST_FORWARD and FORWARD_ONLY are mutually exclusive; if one is specified the other cannot be specified.
READ_ONLY
Prevents updates made through this cursor. The cursor cannot be referenced in a WHERE CURRENT OF clause in an UPDATE or DELETE statement. This option overrides the default capability of a cursor to be updated.
SCROLL_LOCKS
Specifies that positioned updates or deletes made through the cursor are guaranteed to succeed. Microsoft® SQL Server™ locks the rows as they are read into the cursor to ensure their availability for later modifications. SCROLL_LOCKS cannot be specified if FAST_FORWARD is also specified.
OPTIMISTIC
Specifies that positioned updates or deletes made through the cursor do not succeed if the row has been updated since it was read into the cursor. SQL Server does not lock rows as they are read into the cursor. It instead uses comparisons of timestamp column values, or a checksum value if the table has no timestamp column, to determine whether the row was modified after it was read into the cursor. If the row was modified, the attempted positioned update or delete fails. OPTIMISTIC cannot be specified if FAST_FORWARD is also specified.
TYPE_WARNING
Specifies that a warning message is sent to the client if the cursor is implicitly converted from the requested type to another.
select_statement
Is a standard SELECT statement that defines the result set of the cursor. The keywords COMPUTE, COMPUTE BY, FOR BROWSE, and INTO are not allowed within select_statement of a cursor declaration.
SQL Server implicitly converts the cursor to another type if clauses in select_statement conflict with the functionality of the requested cursor type. For more information, see Implicit Cursor Conversions.
UPDATE [OF column_name [,...n]]
Defines updatable columns within the cursor. If OF column_name [,...n] is supplied, only the columns listed allow modifications. If UPDATE is specified without a column list, all columns can be updated, unless the READ_ONLY concurrency option was specified.
Remarks
DECLARE CURSOR defines the attributes of a Transact-SQL server cursor, such as its scrolling behavior and the query used to build the result set on which the cursor operates. The OPEN statement populates the result set, and FETCH returns a row from the result set. The CLOSE statement releases the current result set associated with the cursor. The DEALLOCATE statement releases the resources used by the cursor.
The first form of the DECLARE CURSOR statement uses the SQL-92 syntax for declaring cursor behaviors. The second form of DECLARE CURSOR uses Transact-SQL extensions that allow you to define cursors using the same cursor types used in the database API cursor functions of ODBC, ADO, and DB-Library.
You cannot mix the two forms. If you specify the SCROLL or INSENSITIVE keywords before the CURSOR keyword, you cannot use any keywords between the CURSOR and FOR select_statement keywords. If you specify any keywords between the CURSOR and FOR select_statement keywords, you cannot specify SCROLL or INSENSITIVE before the CURSOR keyword.
If a DECLARE CURSOR using Transact-SQL syntax does not specify READ_ONLY, OPTIMISTIC, or SCROLL_LOCKS, the default is as follows:
If the SELECT statement does not support updates (insufficient permissions, accessing remote tables that do not support updates, and so on), the cursor is READ_ONLY.
STATIC and FAST_FORWARD cursors default to READ_ONLY.
DYNAMIC and KEYSET cursors default to OPTIMISTIC.
Cursor names can be referenced only by other Transact-SQL statements. They cannot be referenced by database API functions. For example, after declaring a cursor, the cursor name cannot be referenced from OLE DB, ODBC, ADO, or DB-Library functions or methods. The cursor rows cannot be fetched using the fetch functions or methods of the APIs; the rows can be fetched only by Transact-SQL FETCH statements.
After a cursor has been declared, these system stored procedures can be used to determine the characteristics of the cursor.
System stored procedure Description
sp_cursor_list Returns a list of cursors currently visible on the connection and their attributes.
sp_describe_cursor Describes the attributes of a cursor, such as whether it is a forward-only or scrolling cursor.
sp_describe_cursor_columns Describes the attributes of the columns in the cursor result set.
sp_describe_cursor_tables Describes the base tables accessed by the cursor.
Variables may be used as part of the select_statement that declares a cursor. However, changes to those variables after the cursor has been declared will have no affect on the cursor's operation.
Permissions
DECLARE CURSOR permissions default to any user that has SELECT permissions on the views, tables, and columns used in the cursor.
Examples
A. Use simple cursor and syntax
The result set generated at the opening of this cursor includes all rows and all columns in the authors table of the pubs database. This cursor can be updated, and all updates and deletes are represented in fetches made against this cursor. FETCH NEXT is the only fetch available because the SCROLL option has not been specified.
DECLARE authors_cursor CURSOR
FOR SELECT * FROM authors
OPEN authors_cursor
FETCH NEXT FROM authors_cursor
B. Use nested cursors to produce report output
This example shows how cursors can be nested to produce complex reports. The inner cursor is declared for each author.
SET NOCOUNT ON
DECLARE @au_id varchar(11), @au_fname varchar(20), @au_lname varchar(40),
@message varchar(80), @title varchar(80)
PRINT "-------- Utah Authors report --------"
DECLARE authors_cursor CURSOR FOR
SELECT au_id, au_fname, au_lname
FROM authors
WHERE state = "UT"
ORDER BY au_id
OPEN authors_cursor
FETCH NEXT FROM authors_cursor
INTO @au_id, @au_fname, @au_lname
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT " "
SELECT @message = "----- Books by Author: " +
@au_fname + " " + @au_lname
PRINT @message
-- Declare an inner cursor based
-- on au_id from the outer cursor.
DECLARE titles_cursor CURSOR FOR
SELECT t.title
FROM titleauthor ta, titles t
WHERE ta.title_id = t.title_id AND
ta.au_id = @au_id -- Variable value from the outer cursor
OPEN titles_cursor
FETCH NEXT FROM titles_cursor INTO @title
IF @@FETCH_STATUS <> 0
PRINT " <<No Books>>"
WHILE @@FETCH_STATUS = 0
BEGIN
SELECT @message = " " + @title
PRINT @message
FETCH NEXT FROM titles_cursor INTO @title
END
CLOSE titles_cursor
DEALLOCATE titles_cursor
-- Get the next author.
FETCH NEXT FROM authors_cursor
INTO @au_id, @au_fname, @au_lname
END
CLOSE authors_cursor
DEALLOCATE authors_cursor
GO
-------- Utah Authors report --------
----- Books by Author: Anne Ringer
The Gourmet Microwave
Is Anger the Enemy?
----- Books by Author: Albert Ringer
Is Anger the Enemy?
Life Without Fear
amin_alexi
شنبه 26 اردیبهشت 1388, 16:13 عصر
اگه تو Books OnLine با Cursor یک Search بزنی یک مثال داره
این Link تو خوده سایت MSDN Online خیلی خوب و واضح توضیح داده آخر صفحه مثال رو ببین خودت می فهمی چه کار باید بکنی !
http://msdn.microsoft.com/en-us/library/ms180169.aspx
mina.net
شنبه 26 اردیبهشت 1388, 19:53 عصر
شما یک فیلد به این Query اضافه کن یا یک View بساز که یک فیلد به عنوان ترتیب داشته باشی اسمشو بزار مثلا ID و به جای tarikh< tarikh+1 از اون ID استفاده کن
سلام دوست عزیز
با عرض معذرت باید بگم که من نمی تونم از این روش استفاده کنم . چون همون طور که قبلا گفته بودم برای کاربر من مهم تاریخ هست نه چیز دیگری .
دو راه هست
راه اول : ما بیایم قبل از گزارشگیری جدول رو به ترتیب تاریخ سورت کنیم و یک ستون تعریف کنیم به نام id و سپس به ترتیب تاریخ بهشون شماره بدیم که البته اگه در یک تاریخ چند سند ثبت شده بود شماره های مختلف خواهد گرفت و سپس براساس id این کار رو انجام بدیم.
راه دوم : اگر امکان این باشد همزمان از شرط دو شرط با اولویت تاریخ استفاده کنیم. البته من شرط رو به شکل tarikh<tarikh+1 and id<id+1 اجرا کرم ولی بازم هم همون نتیجه قبلی رو دیدم.
دو روش بالا فقط تحلیل هست ولی من هنوز موفق نشدم اینکار رو در عمل انجام بدم اگه می شه راهنمایی کنید.
در ضمن ظاهرا باید سعی کنم SQL بیشتر یاد بگیرم.
anooshiran
یک شنبه 27 اردیبهشت 1388, 02:13 صبح
سلام دوست عزيز
با عرض پوزش از تاخير در جواب
يك فايل Backupاز يك database به ضميمه است. لطفا يك database به نام Test بساز و اين backup را در آن restore كن
در اين Datbase يك Table به نام MRZTbl موجود است كه تقريبا از روي نمونه فايل word شما ايجاد شده.
و برنامه ضميمه در بردارنده select مورد نظر شماست. البته بايد عرض كنم كه ابتدا يك view ساخته مي شود و سپس از آن view استفاده مي گردد.
شايد اين يكي از سخت ترين select هايي بوده كه تا كنون نوشته ام.
البته كماكان عقيده دارم كه اين راه حل درستي براي كار شما نيست و خيلي بهتر است كه شما از توانايي هاي خود datagridview براي اين كار استفاده كنيد. به هر حال اميد وارم كه با اين select مشكل شما حل گردد.
اگر مشكل يا سئوالي بود كماكان در خدمت هستم
amin_alexi
یک شنبه 27 اردیبهشت 1388, 09:37 صبح
باور کن مساله رو داری خیلی سخت می کنی !
منم 2 راه رو پیشنهاد میدم !
یکی همون راه که بهت گفتم با تاریخ سورت کنی (راه اول خودت) ، یکی هم استفاده از Cursor !
که استفاده ار Cursor سریعتره ! و لازم هم نیست از امکانات ابزارهای گزارش سازی یا datagridview استفاده کنی ...
mina.net
یک شنبه 27 اردیبهشت 1388, 14:25 عصر
شايد اين يكي از سخت ترين select هايي بوده كه تا كنون نوشته ام.
البته كماكان عقيده دارم كه اين راه حل درستي براي كار شما نيست و خيلي بهتر است كه شما از توانايي هاي خود datagridview براي اين كار استفاده كنيد. به هر حال اميد وارم كه با اين select مشكل شما حل گردد.
سلام دوست عزیز و ممنون از کمکی که انجام دادید. اما روش های ساده تر و در عین حال مفید تر کار با datagridview رو بفرمایید. البته شاید در این تالار جاش نباشد هر جا گذاشتی می رم می بینم اصلا من همیشه مطالب شما رو دنبال می کنم. لازم به یاد آوری هست که در نهایت من گزارش رو باید تو کریستال ریپورت به کاربرم نمایش بدم. و هر راهی که فکر می کنید صحیح تر است بفرمایید. یک پیشنهاد من در بخش VB.net یک تاپیک می زنم و لینک این تاپیک رو هم می دیم چطوره ؟ اگه همگی کمک کنن به یک نتیجه قابل قبول برسیم(به اجماع برسیم)
در ضمن نمی دونم چرا فکر می کنید با select این کار سخت تر هست.
باور کن مساله رو داری خیلی سخت می کنی !
منم 2 راه رو پیشنهاد میدم !
یکی همون راه که بهت گفتم با تاریخ سورت کنی (راه اول خودت) ، یکی هم استفاده از
دوست عزیز من فقط تحلیل کردم که شاید از این طریق بشه ولی اینکه چطور باید به فیلد id مقدار داد برای استفاده رو نمی دونم کمک کنید تا انجام بدم.
یکی هم استفاده از Cursor !
که استفاده ار Cursor سریعتره ! و لازم هم نیست از امکانات ابزارهای گزارش سازی یا datagridview استفاده کنی ...
خوب دوست عزیز همن طور که گفتم من با SQL آشنای کمکی دارم و دارم سعی می کنم نحوه ساختن Cursor رو یاد بگیرم.
mina.net
یک شنبه 27 اردیبهشت 1388, 14:45 عصر
سلام دوستان
موضوع رو در دو تالار کریستال ریپورت و vb.net نیز مطرح کردم تا از جوانب مختلف بررسی شود.
یک خواهش حتما مطالب تاپیکهای زیر را مطالعه کنید و سپس اگر مطلبی دارید فقط در یکی از این سه تاپیک قرار دهید.(vb.net,SQL و کریستال ریپورت)
http://barnamenevis.org/forum/showthread.php?p=723972#post723972
http://barnamenevis.org/forum/showthread.php?p=723974#post723974
anooshiran
یک شنبه 27 اردیبهشت 1388, 20:57 عصر
سلام دوست عزيز
select ي را كه برايت نوشتم دقيقا مشكل شما را حل مي كند.
شما در نهايت نياز داريد كه يا از طريق select ، يك datatable يا يك view تهيه كرده و از آن در كريستال ريپورت استفاده كنيد.
يا اينكه از طريق Datagridview محاسبات مانده هاي خود را انجام دهيد و در نتيجه را در يك datatable ريخنه و در كريستال ريپورت يا هر گزارش ساز ديگري استفاده كنيد.
البته خود گزارش سازها مانند crystal Report يا Active report هم قابليت هايي براي اينگونه مانور ها دارند ولي از لحاظ صرف زمان محاسباتي و ساخت گزارش مقرون به صرفه نيستند بخصوص زماني كه حجم ديتا زياد باشد.
به هر حال اگر از پروژه كوچكي كه برايتان نوشتم استفاده كنيد مشكلتان حل خواهد شد.
به روي چشم من از طريق datagridview هم براي شما اين كار را انجام خواهم داد.
منتظر باشيد
Hamid.Mayeli
سه شنبه 29 اردیبهشت 1388, 15:46 عصر
سلام دوست عزيز
با عرض پوزش از تاخير در جواب
شما بايد در كيريستال يه فرمول تعريف كني، كه در آن Debit - Credit رو حساب كني كه مربوط به هر خط ميشه. بعد از آن Running Total ميگيري و تو Detail ميزاري .
mina.net
سه شنبه 29 اردیبهشت 1388, 16:07 عصر
سلام دوست عزيز
با عرض پوزش از تاخير در جواب
شما بايد در كيريستال يه فرمول تعريف كني، كه در آن Debit - Credit رو حساب كني كه مربوط به هر خط ميشه. بعد از آن Running Total ميگيري و تو Detail ميزاري .
دوت عزیز سلام
یکی از دو لینکی که بالا گذاشتم تو تالار کریستال ریپورت هست لطف کنید اونجا توضیح بیشتری بدید. البته اگه امکانش هست. لینکش رو دوباره می زارم. با تشکر از حسن توجهی که دارید.
http://barnamenevis.org/forum/showthread.php?t=160093
Hamid.Mayeli
پنج شنبه 31 اردیبهشت 1388, 11:35 صبح
دوت عزیز سلام
یکی از دو لینکی که بالا گذاشتم تو تالار کریستال ریپورت هست لطف کنید اونجا توضیح بیشتری بدید. البته اگه امکانش هست. لینکش رو دوباره می زارم. با تشکر از حسن توجهی که دارید.
http://barnamenevis.org/forum/showthread.php?t=160093
تو این لینک برات جواب گذاشتم
vBulletin® v4.2.5, Copyright ©2000-1404, Jelsoft Enterprises Ltd.