Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2005 > SQL Server 2005
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
SQL Server 2005 General discussion of SQL Server *2005* version only.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2005 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #11 (permalink)  
Old April 1st, 2008, 10:54 AM
Authorized User
 
Join Date: Jun 2003
Location: Colombo 04, WP, Sri Lanka.
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Preethi Send a message via Yahoo to Preethi
Default

I am not sure what client tool/application you are using. If you are using SSMS, click on options and goto connection properties. Change the value of Execution timeout.

However this option may give undesired results as a poorly written query may wait for ever and block all other connections from accessing your resources. Use it with care.

G.R.Preethiviraj Kulasingham
Reply With Quote
  #12 (permalink)  
Old April 2nd, 2008, 11:26 PM
Authorized User
 
Join Date: Apr 2007
Location: , , .
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here is the code for my View ..
CREATE VIEW dbo.abc
AS
SELECT a.INVOICE_DETAIL_ID, b.INVOICE_HEADER_ID, a.LINE_ITEM_CODE, c.LINE_ITEM_DESCRIPTION, d.GROUP_TITLE, a.QUANTITY, a.RATE,
                          (SELECT DATE_OCCURRED
                            FROM dbo.INVOICE_DETAIL_DATES
                            WHERE (INVOICE_DETAIL_ID = a.INVOICE_DETAIL_ID) AND (LINE_ITEM_CODE = a.LINE_ITEM_CODE) AND (LINE_ITEM_DATE_ID = 1))
                      AS date_ordered,
                          (SELECT DATE_OCCURRED
                            FROM dbo.INVOICE_DETAIL_DATES AS INVOICE_DETAIL_DATES_5
                            WHERE (INVOICE_DETAIL_ID = a.INVOICE_DETAIL_ID) AND (LINE_ITEM_CODE = a.LINE_ITEM_CODE) AND (LINE_ITEM_DATE_ID = 2))
                      AS date_completed,
                          (SELECT DATE_OCCURRED
                            FROM dbo.INVOICE_DETAIL_DATES AS INVOICE_DETAIL_DATES_4
                            WHERE (INVOICE_DETAIL_ID = a.INVOICE_DETAIL_ID) AND (LINE_ITEM_CODE = a.LINE_ITEM_CODE) AND (LINE_ITEM_DATE_ID = 3))
                      AS date_cancelled,
                          (SELECT DATE_OCCURRED
                            FROM dbo.INVOICE_DETAIL_DATES AS INVOICE_DETAIL_DATES_3
                            WHERE (INVOICE_DETAIL_ID = a.INVOICE_DETAIL_ID) AND (LINE_ITEM_CODE = a.LINE_ITEM_CODE) AND (LINE_ITEM_DATE_ID = 4))
                      AS date_service_begin,
                          (SELECT DATE_OCCURRED
                            FROM dbo.INVOICE_DETAIL_DATES AS INVOICE_DETAIL_DATES_2
                            WHERE (INVOICE_DETAIL_ID = a.INVOICE_DETAIL_ID) AND (LINE_ITEM_CODE = a.LINE_ITEM_CODE) AND (LINE_ITEM_DATE_ID = 5))
                      AS date_service_end,
                          (SELECT DATE_OCCURRED
                            FROM dbo.INVOICE_DETAIL_DATES AS INVOICE_DETAIL_DATES_1
                            WHERE (INVOICE_DETAIL_ID = a.INVOICE_DETAIL_ID) AND (LINE_ITEM_CODE = a.LINE_ITEM_CODE) AND (LINE_ITEM_DATE_ID = 6))
                      AS date_open_date, h.NOTES, a.QUANTITY * a.RATE AS TotalBeforeAdjustments, f.DISPLAY_NAME AS created_by, a.CREATED,
                      g.ADJUST_AMOUNT_BY, g.REASON_FOR_ADJUSTMENT, a.QUANTITY * a.RATE + ISNULL(g.ADJUST_AMOUNT_BY, 0) AS GrandTotal, g.ADJUSTED,
                      i.DISPLAY_NAME AS adjusted_by, k.ADJUSTMENT_REASON
FROM dbo.INVOICE_DETAIL AS a WITH (nolock) INNER JOIN
  dbo.INVOICE_HEADER AS b WITH (nolock) ON a.INVOICE_HEADER_ID = b.INVOICE_HEADER_ID INNER JOIN
  dbo.LINE_ITEMS AS c WITH (nolock) ON a.LINE_ITEM_CODE = c.LINE_ITEM_CODE INNER JOIN
  dbo.LINE_ITEM_GROUPS AS d WITH (nolock) ON a.GROUP_ID = d.GROUP_ID INNER JOIN
  dbo.INVOICE_DETAIL_DATES AS e WITH (nolock) ON a.INVOICE_DETAIL_ID = e.INVOICE_DETAIL_ID INNER JOIN
  ICLEAR_CENTRALDB.dbo.USER_CONTACT_INFO AS f WITH (nolock) ON a.CREATED_BY = f.CONTACT_INFO_ID LEFT OUTER JOIN
  dbo.INVOICE_ADJUSTMENTS AS g WITH (nolock) ON a.INVOICE_DETAIL_ID = g.INVOICE_DETAIL_ID LEFT OUTER JOIN
  dbo.INVOICE_NOTES AS h WITH (nolock) ON a.INVOICE_DETAIL_ID = h.INVOICE_DETAIL_ID LEFT OUTER JOIN
  ICLEAR_CENTRALDB.dbo.USER_ACCOUNTS AS j WITH (nolock) ON g.ADJUSTED_BY = j.ACCOUNT_ID LEFT JOIN
  ICLEAR_CENTRALDB.dbo.USER_CONTACT_INFO AS i WITH (nolock) ON j.CONTACT_INFO_ID = i.CONTACT_INFO_ID LEFT JOIN
  dbo.INVOICE_ADJUSTMENT_REASONS AS k WITH (nolock) ON g.ADJUSTMENT_REASON_ID = k.ADJUSTMENT_REASON_ID


Thanks.

Gunjan
Reply With Quote
  #13 (permalink)  
Old April 2nd, 2008, 11:54 PM
Friend of Wrox
Points: 1,536, Level: 15
Points: 1,536, Level: 15 Points: 1,536, Level: 15 Points: 1,536, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2006
Location: , MI, USA.
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts
Default

You have 6 correlated sub-queries and that will definitely slow things down... a lot...

I recommend you convert them into a single derived table using a cross-tab. That information is in Books Online under "Cross Tab"

--Jeff Moden
Reply With Quote
  #14 (permalink)  
Old April 3rd, 2008, 05:28 AM
Authorized User
 
Join Date: Apr 2007
Location: , , .
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
I am using SQL server 2000..
And it doesn't recognize ROW_NUMBER() function


Thanks.

Gunjan
Reply With Quote
  #15 (permalink)  
Old April 3rd, 2008, 06:15 AM
Friend of Wrox
Points: 1,536, Level: 15
Points: 1,536, Level: 15 Points: 1,536, Level: 15 Points: 1,536, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2006
Location: , MI, USA.
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts
Default

Cross Tab has nothing to do with Row_Number()...

Also, you really should post you SQL Server 2000 questions in the SQL Serve 2000 forum so people don't waste their time trying to answer you with the wrong technology.

--Jeff Moden
Reply With Quote
  #16 (permalink)  
Old April 9th, 2008, 05:51 AM
Authorized User
 
Join Date: Jun 2003
Location: Colombo 04, WP, Sri Lanka.
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Preethi Send a message via Yahoo to Preethi
Default

I am not writing the entire code here.. My only concern is your sub queries.

You need to re-write them
This could be a way of writing. Please go and add additional columns to like to other tables

Code:
SELECT MAX(date_ordered) AS date_ordered, 
    MAX(date_completed) AS date_completed, 
    MAX(date_cancelled) AS date_cancelled, 
    MAX(date_service_begin)  AS date_service_begin, 
    MAX(date_service_end)  AS date_service_end, 
    MAX(date_open_date)  AS date_open_date
FROM 
(

    SELECT a.INVOICE_DETAIL_ID, b.INVOICE_HEADER_ID, a.LINE_ITEM_CODE, c.LINE_ITEM_DESCRIPTION, d.GROUP_TITLE, a.QUANTITY, a.RATE,  
    CASE LINE_ITEM_DATE_ID WHEN 1  THEN DATE_OCCURRED ELSE '01/01/1900' END AS date_ordered,
    CASE LINE_ITEM_DATE_ID WHEN 2  THEN DATE_OCCURRED ELSE '01/01/1900' END AS date_completed,
    CASE LINE_ITEM_DATE_ID WHEN 3  THEN DATE_OCCURRED ELSE '01/01/1900' END AS date_cancelled,
    CASE LINE_ITEM_DATE_ID WHEN 4  THEN DATE_OCCURRED ELSE '01/01/1900' END AS date_service_begin,
    CASE LINE_ITEM_DATE_ID WHEN 5  THEN DATE_OCCURRED ELSE '01/01/1900' END AS date_service_end,
    CASE LINE_ITEM_DATE_ID WHEN 6  THEN DATE_OCCURRED ELSE '01/01/1900' END AS date_open_date
    FROM          dbo.INVOICE_DETAIL_DATES  
    WHERE      (INVOICE_DETAIL_ID = a.INVOICE_DETAIL_ID) AND (LINE_ITEM_CODE = a.LINE_ITEM_CODE)
) A
G.R.Preethiviraj Kulasingham
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Datagrid taking huge render time gunjan.sh ASP.NET 2.0 Basics 1 June 4th, 2008 07:40 AM
MTOM taking more time than base64 method shahzadgodil .NET Web Services 0 February 27th, 2007 02:51 AM
How to work through huge amounts of data effective Planet_Jeroen Excel VBA 2 January 16th, 2007 08:12 AM
taking particular data .. anukagni Access 2 August 4th, 2006 12:05 AM
Autofilter taking too much of time raaghu15 Excel VBA 2 March 4th, 2005 05:43 PM



All times are GMT -4. The time now is 09:01 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.