Table Query Timeout Problem Very Specific

Aug 26, 2006

MSSQL Server 2000 SP3 in both houston and memphis

I have a database in houston, lets call it RED. Specific tables from
database RED are copied to database BLUE. Database BLUE is then backed
up, ftp'd to memphis and restored. In memphis there is a single table
in this database that will not open in enterprise manager when you
choose to open all rows you get a generic ODBC timeout error no numbers
just simply "TIMEOUT".

If I log into the servers in houston and open the table from database
RED or BLUE there is no issue. I can however return up to 66,199 rows
without an error. If i choose a number higher than this i get the
timeout error. I discovered I could run a query

Select Distinct * from f0911

and it would display all my data. I am able to export the data from
the table using this query to a csv file and reimport the data into a
table and it works just fine.

I built another sql 2000 server SP4 and there is no issue with the
table in the database when it is restored there. I have also tried
restoring as a different database name on the production (sql 2000 sp3)
server to no avail.

I can't figure out why this single table is not functioning properly in
the one instance of sql 2000.

If anyone has any ideas please share them, I'm running out myself. I'm
obviously very new at sql database administration and would appreciate
any advice.


Also, i don't believe the issue has to do with timeout countdowns.
Everywhere i could change them (Enterprise manager and SQL Server
itself) they are set to unlimited if possible. I also don't see how
the problem could be related to the service pack of the sql server,
seeing as although it works on the sp4 server in my possession it still
works just fine on the sp3 server in houston.

Thanks,

Michael Smith

View 1 Replies


ADVERTISEMENT

Want To Query One Specific Record From Database Table

Feb 27, 2008

I have two tables in my database: order_id with fields order (text) and comp_ID (int) and another table called customers with comp_ID (int) and company name (text) and other company information fields. The link between the two tables is the comp_ID. With every order that's made the company that made the order is stored with it in the order_id table.  If I type in the order id (text), I want to be able to use the order id to search the order_id table and find out what the comp_ID of the company that made that order is. Then use that comp_ID to pull up the record of company information from the customers table with the same comp_ID. Is there some way to do this in one query? Or how do I accomplish this?  

View 4 Replies View Related

Query File Table And Get Document For Specific Product

Feb 11, 2015

Lest Say with File-stream we have a table document where the file-stream column is located, then we have another table called product-document where the productID and the Document-node are both foreign key of the Product and the Document tables respectively. if i want to query the file-stream document for a specific product, i can just join all three tables, but with file-table there is something i probably didn't get as how to query the file table and get a document for a specific product.

View 0 Replies View Related

Can Logging Be Turned Off On Inserts To A Specific Temp Table From A Specific Sp?

Oct 10, 2007

I want to ship 500,000 aged transactions each night to an archive table and delete them from their source table in one or more logical units of work (LUW). Each row is approx 60 bytes and there is only one non clustered index on the source table presently.

I'm trying to weigh the pros and cons of 3 alternatives. One of them would basically insert the non-aged rows into tempdb, ship the aged records, truncate the table and then insert the tempdb records back into their source all in the same LUW.

For this alternative, I'd at least like to turn off logging when the records get inserted into tempdb as I dont see any value in logging that part of the activity. Is this possible?

View 4 Replies View Related

Difference Between Remote Login Timeout And Remote Query Timeout?

Mar 28, 2008

I just want to find out what the difference between a remote login and a remote query is. I'd have thought that a remote query inherently requires a remote login.

View 6 Replies View Related

Stored Procedure Query Optimization - Query TimeOut Error

Nov 23, 2004

How to optimize the following Stored procedure running on MSSQL server 2000 sp4 :

CREATE PROCEDURE proc1
@Franchise ObjectId
, @dtmStart DATETIME
, @dtmEnd DATETIME
AS
BEGIN


SET NOCOUNT ON

SELECT p.Product
, c.Currency
, c.Minor
, a.ACDef
, e.Event
, t.Dec
, count(1) "Count"
, sum(Amount) "Total"
FROM tb_Event t
JOIN tb_Prod p
ON ( t.ProdId = p.ProdId )
JOIN tb_ACDef a
ON ( t.ACDefId = a.ACDefId )
JOIN tb_Curr c
ON ( t.CurrId = c.CurrId )
JOIN tb_Event e
ON ( t.EventId = e.EventId )
JOIN tb_Setl s
ON ( s.BUId = t.BUId
and s.SetlD = t.SetlD )
WHERE Fran = @Franchise
AND t.CDate >= @dtmStart
AND t.CDate <= @dtmEnd
AND s.Status = 1
GROUP BY p.Product
, c.Currency
, c.Minor
, a.ACDef
, e.Event
, t.Dec

RETURN 1
END



GO

View 8 Replies View Related

Copying Specific Data From Table In DB1 To Table In DB2

Feb 22, 2006

I need to copy the following columns from my Employee table in my Performance DB to my Employee table in my VacationRequest DB: CompanyID, FacilityID, EmployeeID, FirstName, LastName, [Password] = 'nippert', Role = 'Employee' I tried the advice on this website but to no avail:http://www.w3schools.com/sql/sql_select_into.asp

View 1 Replies View Related

Help On Specific Query

Apr 12, 2008

Hello Valueable Friends , I have an issue and i am going to need a help..

I have a rents table with fields that matter now
Stuffid , rentdate , rentCustomer ........

On my stuff table i Added a new field called LastCustRent

So I want to update this field With the Customerid that rented each
stuff last time

I tried this




Select Stuffid ,max(rentdate) as maxrentdate , rentcust
from rents
Group by rentcust , stuffid




But I do not take unique results

Can someone help me on how will i get only the customer of my last rent time for each stuffid on my rents table?


I sell my mother in law.Is anybody interested?

View 4 Replies View Related

Query Timeout???

Jul 8, 2007

I try to run a sql query locally and iget the results, but when i try remotely from my website, after 10 seconds i get a query timeout. The query timeout is set to 0, i do not know what am i doing wrong?

View 17 Replies View Related

Query Timeout

Aug 17, 2006

I need to figure out if my query is timing out due to row lock contention. The SqlException trapped in my client C# application contains Error Number 1205 but sometimes it contains -2.

I guess the SqlCommand timeout and the server timeout are the two possibilities. Is there a definitive way to find out that the SqlException was thrown due to one of these two reasons? Because if it's some other reason, I want to excute a different logic.

Thanks,



Madhav

View 4 Replies View Related

Query To Get Column Name With Specific Value

Jul 20, 2005

Here is tested schemaif exists (select * from dbo.sysobjects where id =object_id(N'[dbo].[TestTable]') and OBJECTPROPERTY(id, N'IsUserTable')= 1)drop table [dbo].[TestTable]GOCREATE TABLE [dbo].[TestTable] ([SerialNumber] [char] (12) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,[test1] [char] (4) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,[test2] [char] (4) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,[test3] [char] (4) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,[test4] [char] (4) COLLATE SQL_Latin1_General_CP1_CI_AS NULL) ON [PRIMARY]GOinsert into testtable values ('123','pass',null,'fail','skip')insert into testtable values ('456','fail',null,'pass','skip')insert into testtable values ('789',null,'fail','skip','pass')insert into testtable values ('345','pass','pass','pass','fail')I would like to fetch the COLUMNNAME where the value is fail.Basically I need to know which test failed, test1, test2, test3 ortest4?Is this possible?

View 2 Replies View Related

Looking For The Specific Value In Whole Table..

May 8, 2008



I am trying to count the number of value "99" for each column in the whole table
to see how many "99" are there per column for the whole table...
and get the percentage per each column.. How can I do this for the whole table?




output should look like

Column A 117 10%
Column B 120 14%
-- etc..

View 2 Replies View Related

Query Timeout Setting

Oct 29, 2007

SQL Server 2005 is timing out when running loooong queries.Is there a global place I can extend the timeout for queries? I do not mean in code but just in general use?Thanks
 
Craig

View 5 Replies View Related

SQL Query Analyzer Timeout

Jan 9, 2002

I was working remotely with few SQL Servers for a while without any problem.
The Servers are configured to use TCP-IP for the connection.

Then suddenly today I can connect to the servers in the Enterprise manager , but
not through the SQL Query Analyzer.

The error I am getting after waiting for a while the login ... Timeout Expired.

I've tried changing the Connection Settings under Options, but it did not help.

Nothing was changed in the Server/Client configuration.

Please advice

View 1 Replies View Related

SQL Query Analyzer Timeout

Jan 8, 2002

I was working remotely with few SQL Servers for a while without any problem.
The Servers are configured to use TCP-IP for the connection.

Then suddenly today I can connect to the servers in the Enterprise manager , but
not through the SQL Query Analyzer.

The error I am getting after waiting for a while the login ... Timeout Expired.

I've tried changing the Connection Settings under Options, but it did not help.

Nothing was changed in the Server/Client configuration.

The Servers affected are SQL 7.0. and SQL 2000

Please advice

View 1 Replies View Related

How To Change Query Timeout?

Feb 9, 2005

Greetings

I have encountered the following problem:

I currently develop an application for my company that actually uses rather long queries, with many records.

I have a particular query (Written using SQL string inside the .NET application rather than Stored proceedures),that needs to run in 2 databases (both SQL Server):

The first one is a test database that we use when in developing time quota to test our data

The second one is the real thing a data base that contains lots of records.

When criteria are placed in the query, it returs few records in both the databases , but if no criteria are placed (So it fetches all the records..) In the test Database works ok, but in the real one it "jams" till 30 seconds pass and I get a time out message...

I tried to change the Query time out time from inside the SQL Server from

Tools/Options/Advanced

but it doesn't seem to work out... it still times out after 30 secs

Any Ideas?

Thanx in advance :D

View 4 Replies View Related

Query Timeout Problems

Jul 23, 2005

Front End: Access 2000 Project (.adp)Back End: SQL Server 2000I have an application that keeps timing out. I have opened theDataLink properties in the front end (File, Connection, Advanced tab)and set the timeout to 999. But the connection still occasionallytimes out.Any ideas? Some of the SQL is pretty horrible (multiple sub-queriesetc.)TIAEdward--The reading group's reading group:http://www.bookgroup.org.uk

View 1 Replies View Related

Strange Query Timeout

Jul 20, 2005

Hi everibody,it's the first time i post on this newsgroup. I'm Stefano from Milano,italy.I'm a beginners with Sql2000. My problem is this.I run a View using enterprise manager and after less then 20 second it goesin error time out. I run this view using a VB application and the errorcomes again .When i run it with Query Analyzer after 50 seconds it give methe right result.i've tried to change the value of querytimeout using sp_configure with thesame bad result.i've tried to change the ado command timeout in visul basic but stilldoesn't work.any suggest ?Thanks in advance

View 4 Replies View Related

SQL Timeout Through ADO But Not From Query Analyser

Jan 12, 2007

I have a strange problem running a stored proc in SQL 2000. The proc returns XML and I'm using ADO to call the proc and return the data as a stream. When I call the proc through ADO, it times out because it is taking 40 seconds to run and my command timeout is set to 30. I can increase this no problem but the strange thing is that when I run the same proc from within query analyser, it completes in under a second.

I put profiler on it tracing the command start and finish events and it's definitely taking 40 seconds between start and finish. The proc is used with various input parameters and the timeout is only occurring for some combinations of inputs, but it always seems to take much longer than it does when run from query analyser.

Can anyone suggest what might be causing the delay, or where I might look to find the problem?

Thanks...

View 13 Replies View Related

Problem With Query Timeout

Jan 15, 2008

Hallo,

I have the following Query running on my local SQL Server 2005 Standard Edition on Windows XP, and it needs only 2 sec. to execute. Then I transfered it to our production database, which is an SQL Server 2005 Datacenter Edition on a quad-core Xeon with 4GB Memory and the Query always runs in a Timeout. The version of my local Database is 9.0.3054 and the Production Version is 9.0.3042. 3042 seems to be SP2.

Here the Query:


SELECT i.lid AS userlid, i.lgroupid AS grouplid, i.strgroupname, j.xgssnid

FROM (SELECT kruser.lid, kruser.stremployeeno, krgroupusers.lgroupid, krusergroup.strgroupname

FROM kruser INNER JOIN krgroupusers ON kruser.lid = krgroupusers.luserid

INNER JOIN krusergroup ON krgroupusers.lgroupid = krusergroup.lid

WHERE (NOT (kruser.strusername LIKE 'i_%')) AND

(kruser.stremployeeno <> '') AND

(kruser.stremployeeno IS NOT NULL)

) AS i

LEFT OUTER JOIN

(SELECT TOP (100) PERCENT xgssnid, AppRolle

FROM (SELECT DISTINCT xwebmodul + '_' + xrolle AS AppRolle, xgssnid

FROM xzztmpuserimport

UNION

SELECT DISTINCT 'nav_' + xwebmodul AS AppRolle, xgssnid

FROM xzztmpuserimport AS a

) AS b

ORDER BY xgssnid, AppRolle

) AS j

ON i.stremployeeno = j.xgssnid AND i.strgroupname = j.AppRolle

WHERE (i.lgroupid > 105) AND (i.lid > 100) AND

(NOT (i.strgroupname LIKE 'i_%')) AND

(j.xgssnid IS NULL)



This Query filters all internal Applicationroles of a user which must be deleted for the specific user, because he didn't need them longer. Can it be, that it was a bug in the older Servicepack and it runs on my PC because of the newer one? My problem is also, that I didn't know what ServiecPack brings Version 3042 to 3054.

I also tried splitting the Query in 3 subqueries and using this 3 in a resulting 4th. It's the same!

Has anyone an idea

Thanks for your help
Hans

View 5 Replies View Related

Datareader Query Timeout

Oct 4, 2005

Hello,

View 16 Replies View Related

Query Timeout Expired

Jan 16, 2006

Using VB, I am running a bulk insert query from csv file into a newly created table. It works fine on small test files; but when I try it on the production data, I get a "query timeout expired" message and processing ends. The text files contain several hundred thousand lines.

How can I resolve this problem. I have several hundred of these csv files and more coming.

Here's the code:

Dim sSQL As String
sSQL = "BULK INSERT " & TableName & " "
sSQL = sSQL & "FROM '" & DataPath & "' WITH "
sSQL = sSQL & "(FIELDTERMINATOR = ',', ROWTERMINATOR = '', FIRSTROW = 2)"

DbConn.Execute sSQL

View 6 Replies View Related

How Always Keep Specific Query In Procedure Cache ?

Jun 1, 2001

Is any way we can tell sql server to keep specific (long runing) query in procedure Cache.
I already tried to do this by creating job (run every 1 hr from 8 am to 6 pm)
but is not enough

Thanks

View 1 Replies View Related

Sql Query Fails At Specific Times

Dec 11, 2003

Hi,

I'm in an unfortunate situation. We are posting information using a stored procedure to an outside SQL server connected to through a System DSN on our server (win 2003 server) using php's ODBC functions (we never had any luck connecting directly to the SQL server using php's mssql functions).

Everything is working fine, we can connect, send querys, etc ... but between 1am and 10am we recieve errors when trying to execute queries (though we can connect fine).


Whoops ... forgot to get the error returned before it turned 10am ... I can post it tomorrow


I think the database is being locked, but unfortunately I know very little about MS SQL server

The people who's database we are connecting to are not being helpful ... I was hoping I could get some suggestions on what would be the cause.

Anything you can suggest would be a huge help! Thanks!
- Joe

View 2 Replies View Related

Slow Performance On Specific Query

Jul 23, 2005

Hi,Can't post specifics at the moment but if this seems like a commonproblem any help would be appreciated.When querying with ~6 tables, using mostly left outer joins, I getstandard performance with the where clausewhere XXX is not nullhowever, if I try the clausewhere XXX = 4the query takes upwards of 5-6 minutes (I just stop it running at thatpoint.The field XXX is in the 'main' table (to which the joins attach), it'san integer field too so I can't see too many problems there.There's no index on the XXX field, but if I remove the joins, I getstandard performance doing either query.So why would the second query's performance differ so significantly?Cheers,Chris

View 3 Replies View Related

Get Specific Range Of Character Through Query

Mar 19, 2008

Hi !
i have a query like select top 3 column1 from table 1 order by Id desc

here the column1 is of varchar(512) data type but i want to get only first 250 chars of it and if they are less than 250 then get the whole range

plz let me know how it is possible throguh query or any other way

Regards,

View 1 Replies View Related

How To Add New Table Under Specific User?

Jun 14, 2004

I'm new to SQL Server.

I've an online Database on a server. I've my own user name like "AKR". I want to create every table under that user. But what happens is whenever I create a table online it goes under "DBO" user name. How to avoid that?

Thanks

View 1 Replies View Related

Count The Specific Value In The Whole Table

May 8, 2008

I am trying to count the number of value "99" for each column in the whole table
to see how many "99" are there per column for the whole table...
and get the percentage per each column.. How can I do this?

output should look like

Column A 117 10%
Column B 120 14%
-- etc..

View 1 Replies View Related

How To Get Specific Rows From Table

Aug 24, 2006

hi

i m using row count in order to get first 16 rows from a specific table...now i want to get rows from row no. 16 to 32 (or any no which i want)...can any one tell meee how can i query it using sql server 200





View 3 Replies View Related

Transact SQL :: Select Specific Values From All Rows Where Value Of A Specific Column Is (Active)

May 23, 2015

I need to select specific values from all rows where the value of a specific column is "Active"

This part works: SELECT LastName, FirstName, MiddleInit, ClientId FROM dbo.Client

But I want to add: WHERE StatusType = (Active) and how to do this.

View 4 Replies View Related

Timeout For Query Inside BEGIN_INIT

Jun 8, 2007

Hi all,
I have a website under development. when trying to load page for the first time, I am getting sometimes a timeout error messege.
My guess is that one of the queries is problematic and takes too long. I need to track the problematic query. one way to do that is using the ASP trace option.
So this is what I did and I got the below error. the error as I can see is inside a BEGIN_INIT function, but I dont have a fnction like this in my code.
Do you have any suggestion how to track? here is the trace code:
Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.210


span.tracecontent b { color:white }
span.tracecontent { background-color:white; color:black;font: 10pt verdana, arial; }
span.tracecontent table { clear:left; font: 10pt verdana, arial; cellspacing:0; cellpadding:0; margin-bottom:25}
span.tracecontent tr.subhead { background-color:#cccccc;}
span.tracecontent th { padding:0,3,0,3 }
span.tracecontent th.alt { background-color:black; color:white; padding:3,3,2,3; }
span.tracecontent td { color: black; padding:0,3,0,3; text-align: left }
span.tracecontent td.err { color: red; }
span.tracecontent tr.alt { background-color:#eeeeee }
span.tracecontent h1 { font: 24pt verdana, arial; margin:0,0,0,0}
span.tracecontent h2 { font: 18pt verdana, arial; margin:0,0,0,0}
span.tracecontent h3 { font: 12pt verdana, arial; margin:0,0,0,0}
span.tracecontent th a { color:darkblue; font: 8pt verdana, arial; }
span.tracecontent a { color:darkblue;text-decoration:none }
span.tracecontent a:hover { color:darkblue;text-decoration:underline; }
span.tracecontent div.outer { width:90%; margin:15,15,15,15}
span.tracecontent table.viewmenu td { background-color:#006699; color:white; padding:0,5,0,5; }
span.tracecontent table.viewmenu td.end { padding:0,0,0,0; }
span.tracecontent table.viewmenu a {color:white; font: 8pt verdana, arial; }
span.tracecontent table.viewmenu a:hover {color:white; font: 8pt verdana, arial; }
span.tracecontent a.tinylink {color:darkblue; background-color:black; font: 8pt verdana, arial;text-decoration:underline;}
span.tracecontent a.link {color:darkblue; text-decoration:underline;}
span.tracecontent div.buffer {padding-top:7; padding-bottom:17;}
span.tracecontent .small { font: 8pt verdana, arial }
span.tracecontent table td { padding-right:20 }
span.tracecontent table td.nopad { padding-right:5 }






Request Details

Session Id:
sesqltrnnbq35g45fxkyqk45
Request Type:
GET

Time of Request:
6/9/2007 12:36:41 AM
Status Code:
500

Request Encoding:
Unicode (UTF-8)
Response Encoding:
Unicode (UTF-8)




Trace Information

Category
Message
From First(s)
From Last(s)

aspx.page
Begin PreInit



aspx.page
End PreInit
4.97502699318581
4.975027

aspx.page
Begin Init
5.03576665047642
0.060740

Unhandled Execution Error
Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.  at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)  at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)  at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)  at System.Data.SqlClient.SqlConnection.Open()  at System.Web.DataAccess.SqlConnectionHolder.Open(HttpContext context, Boolean revertImpersonate)  at System.Web.DataAccess.SqlConnectionHelper.GetConnection(String connectionString, Boolean revertImpersonation)  at System.Web.UI.WebControls.WebParts.SqlPersonalizationProvider.GetConnectionHolder()  at System.Web.UI.WebControls.WebParts.SqlPersonalizationProvider.LoadPersonalizationBlobs(WebPartManager webPartManager, String path, String userName, Byte[]& sharedDataBlob, Byte[]& userDataBlob)  at System.Web.UI.WebControls.WebParts.PersonalizationProvider.LoadPersonalizationState(WebPartManager webPartManager, Boolean ignoreCurrentUser)  at System.Web.UI.WebControls.WebParts.WebPartPersonalization.Load()  at System.Web.UI.WebControls.WebParts.WebPartManager.OnInit(EventArgs e)  at System.Web.UI.Control.InitRecursive(Control namingContainer)  at System.Web.UI.Control.InitRecursive(Control namingContainer)  at System.Web.UI.Control.InitRecursive(Control namingContainer)  at System.Web.UI.Control.InitRecursive(Control namingContainer)  at System.Web.UI.Control.InitRecursive(Control namingContainer)  at System.Web.UI.Control.InitRecursive(Control namingContainer)  at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
8.31843797517178
3.282671

View 3 Replies View Related

Slow Query; Timeout After 30 Seconds

Aug 17, 2004

Hello there,

I am programming with visual basic and I have a large query wich takes too long for execution. After 30 seconds I get a timeout error.

Is there any way to raise the timeout to 90 seconds or something.

I'm using the following connection string to connect to the database.

Provider=SQLOLEDB.1;Connect Timeout=2;Password=****;Persist Security Info=True;User ID=user;Initial Catalog=test;Data Source=sqlserver

thank you

View 4 Replies View Related

Strang Query Timeout Error

Mar 19, 2008

I have created a stored procedure which searches one or more requests (request is a table) according to the given parameters and returns Rows from Request table. I have used Full Text Search function i.e. Contains() in this Query. I have problem with Full Text search, when user first time executes query with Contains() function it works fine and continues working fine for 10 to 15 times or more executions. But after some searches the system starts saying Timeout Error. The very strange situation is that the application is developed in Visual Basic and if we run stored procedure through Visual Basic it says Time Out but at the same time when we run the same stored procedure with same parameters from SQL Server Management Studio, it runs immediately and takes no time in execution. Also I have tested the Stored procedure without the Contains function and in this case it works fine. It only hangs when we search for more than 10 or 15 times.


Does anyone know what is the problem here?, i am posting here my code too,




Code Snippet
-- =============================================
-- Author: Arsalan Tamiz
-- Create date: 17-Mar-2007
-- Description: Request Search Engine
-- =============================================
ALTER PROCEDURE [RVO].[LookUpRequest]

-- Add the parameters for the stored procedure here
@Account_ID int = NULL,
@Comp_Name varchar(255) = NULL,
@RVO_ID varchar(100) = NULL,
@RVO_CreateDateStart datetime = NULL,
@RVO_CreateDateEnd datetime = NULL,
@RVO_LockStatus int = NULL, -- NULL = All, 0 = Not Locked / Open, 1 = Locked
@RVO_FinalizeStatus int = NULL, -- NULL = All, 0 = Not Finalized, 1 = Finalized
@SEStatus int = NULL, -- NULL = NOT use, 0 = NOT set, 1 = SET to any
@SE_ID varchar(100) = NULL, -- SE ID
@RVO_CommitStatus int = NULL, -- NULL = All, 0 = Not Commit, 1 = Committed
@RVO_Voided int = NULL, -- NULL = All, 0 = Not Voided, 1 = Voided
@Area_IDNotSet bit = NULL,
@NH_IDNotSet bit = NULL,
@LandmarkNotSet bit = NULL,
@ClassNotSet bit = NULL,
@City_ID int = NULL,
@Area_ID int = NULL,
@NH_ID int = NULL,
@Keyword varchar(255) = NULL,
@Brand varchar(255) = NULL,
@CompType_ID int = NULL
AS
BEGIN

-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

DECLARE @kc varchar(255);

If @Keyword IS NULL

SET @kc = @Keyword;
Else

SET @kc = Gen.GetContainsCriteriaGen(@Keyword);


SELECT *
FROM RVO.tbl_RequestRVO
WHERE

(@CompType_ID IS NULL OR CompType_ID = @CompType_ID) AND
(

@kc IS NULL OR

Contains(RVO_Keywords, @kc)
) AND
(

@Brand IS NULL OR

Exists(

SELECT * FROM RVO.tbl_RequestRVOBrand


WHERE Brand_Name LIKE @Brand + '%' AND Request_ID = RVO.tbl_RequestRVO.Request_ID
)
) AND
(

(
@City_ID IS NULL AND
@Area_ID IS NULL AND
@NH_ID IS NULL AND
@Area_IDNotSet IS NULL AND
@NH_IDNotSet IS NULL
) OR
Exists(


SELECT * FROM RVO.tbl_RequestRVOAddress


WHERE (


@Area_IDNotSet IS NULL OR
(@Area_IDNotSet = 1 AND Area_ID IS NULL)
) AND

(

@NH_IDNotSet IS NULL OR
(@NH_IDNotSet = 1 AND NH_ID IS NULL)
) AND
(@City_ID IS NULL OR City_ID = @City_ID) AND
(@Area_ID IS NULL OR Area_ID = @Area_ID) AND
(@NH_ID IS NULL OR NH_ID = @NH_ID) AND
Request_ID = RVO.tbl_RequestRVO.Request_ID AND
Address_Voided = 0
)
) AND
(

@LandmarkNotSet IS NULL
OR
NOT Exists (


SELECT TOP 1 *
FROM RVO.tbl_RequestRVOAddressLandmark

INNER JOIN RVO.tbl_RequestRVOAddress ON RVO.tbl_RequestRVOAddressLandmark.RequestAddress_ID = RVO.tbl_RequestRVOAddress.RequestAddress_ID
WHERE Request_ID = RVO.tbl_RequestRVO.Request_ID AND

Address_Voided = 0
)
) AND
(

@ClassNotSet IS NULL
OR
NOT Exists (


SELECT TOP 1 *
FROM RVO.tbl_RequestRVOClass
WHERE Request_ID = RVO.tbl_RequestRVO.Request_ID
)
) AND
(Account_ID = @Account_ID OR @Account_ID IS NULL) AND
(@Comp_Name IS NULL OR RVO_CompName LIKE @Comp_Name) AND
(@RVO_ID IS NULL OR RVO_ID = @RVO_ID) AND
(RVO_CreateDate >= @RVO_CreateDateStart OR @RVO_CreateDateStart IS NULL) AND
(RVO_CreateDate <= @RVO_CreateDateEnd OR @RVO_CreateDateEnd IS NULL) AND
(

@RVO_LockStatus IS NULL OR
(RVO_LockDate IS NULL AND @RVO_LockStatus = 0) OR
(RVO_LockDate IS NOT NULL AND @RVO_LockStatus = 1)
) AND
(

@RVO_FinalizeStatus IS NULL OR
(MO_FinalizeDate IS NULL AND @RVO_FinalizeStatus = 0) OR
(MO_FinalizeDate IS NOT NULL AND @RVO_FinalizeStatus = 1)
) AND
(

@RVO_CommitStatus IS NULL OR
(Comp_ID IS NULL AND @RVO_CommitStatus = 0) OR
(Comp_ID IS NOT NULL AND @RVO_CommitStatus = 1)
) AND
(

( -- if SE = SET Then SE_ID must NOT be NULL

@SEStatus = 1 AND
(

(SE_ID IS NOT NULL AND @SE_ID IS NULL) OR
(SE_ID = @SE_ID)
)
) OR
(@SEStatus = 0 AND SE_ID IS NULL) OR
@SEStatus IS NULL
) AND
(RVO_Voided = @RVO_Voided OR @RVO_Voided IS NULL)
ORDER BY

Account_ID, RVO_CreateDate;



END

View 6 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved