Unruly Query With 2500+ In The &"IN&" List

May 16, 2008

Hello All

I have inherited another team's database and I'm going through the process of documenting and looking for things to optimize and tune.

I just ran across a query like this:

Select AccountName, AccountNumber, DepartmentName, AccountStartDate,AccountEndDate From tblAccount Where AccountNumber IN ( and there is a list of over 2,500 accounts listed. I couldn't believe my eyes. I gotta' believe that this query would not peform very well under these conditions. Plus the table doesn't have a primary key or even an index.

I just had to rant to someone.

Thanks!
- will

View 3 Replies


ADVERTISEMENT

SQL 2000 And 2500 Installed

Mar 27, 2007

can I have on the same computer MS SQL 2000 and and MS SQL 2500 installed ?
of course not runing at the same time
I need it because our customers have both and I must test the applications on the 2 databases

is there any known problems ?

thank you

View 4 Replies View Related

Items In List A That Don't Appear In List B (was Simple Query...I Think)

Jan 20, 2005

Ok, I want to write a stored procedure / query that says the following:
Code:
If any of the items in list 'A' also appear in list 'B' --return false
If none of the items in list 'A' appear in list 'B' --return true


In pseudo-SQL, I want to write a clause like this

Code:

IF
(SELECT values FROM tableA) IN(SELECT values FROM tableB)
Return False
ELSE
Return True


Unfortunately, it seems I can't do that unless my subquery before the 'IN' statement returns only one value. Needless to say, it returns a number of values.

I may have to achieve this with some kind of logical loop but I don't know how to do that.

Can anyone help?

View 3 Replies View Related

Query A List Of Databases

Oct 23, 2006

anyone know how to query a list of databases?

current the sp_helpdb seems cant help me, because it query all the details, i want to do it like select * from database where database id=2

View 5 Replies View Related

SELECT IN List Query

Apr 2, 2008

I have a table that has a list of skills, ie "HP One", "HP Two"

I need to pass the these skills from my applications search page to a stored procedure, hence I have a snippet of the SP below.

DECLARE @SkillSet NVarChar (200)
SET @SkillSet = '-HP One-,-HP Two-'
SET @SkillSet = Replace(@SkillSet, '-', '''')
SELECT * FROM CPSkillMatrixLevels WHERE SkillMatrixLevelName IN (@SkillSet)

The following sp does not return any results, but when i set the last line to ..

SELECT * FROM CPSkillMatrixLevels WHERE SkillMatrixLevelName IN ('HP One', 'HP Two')

It returns a set of results. Also when I do a select on the variable @SkillSet, ie SELECT @SkillSet, it displays 'HP One', 'HP Two'

Can enybody help me here, i Know i'm doing something wrong, but I cant think of what it is.

Thanks

View 6 Replies View Related

Query To List All Indexes In Db

Oct 17, 2007

Can someone help me with Query to list all indexes (name, table, field etc.) on a particular user/dbo database in sqlserver.

Thanks

View 3 Replies View Related

SQL Query To Check Against A List

Jul 23, 2005

SQL gurus...I have one table of items that is the master file. We will call this Table A.I have another table that contains few, some or all items from Table A. Wewill call this Table B.I want to run a query that compares the list of items on Table B against themaster list on Table A.If the item is not present on Table B, show it in the SQL results.Best way to achieve this? I am looping and doubling results in my sql tries.Jeff--Message posted via http://www.sqlmonster.com

View 1 Replies View Related

Query SharePoint List

Jan 31, 2008



Does anyone have any way to run a query against Sharepoint to return the content of a list through transact SQL?. Perferably without having to go throught the "back door" and access the Sharepoint database directly?

Thanks

View 1 Replies View Related

SQL Statement - Query A List Of Values

Oct 31, 2006

Hello  I have a newbie question.  If I have a table of the form:Table1{id, name} with the valuesid: 9 , name: test1,id: 7 , name: test2,id: 3 , name: test3,id: 15 , name: test4, id: 5 , name: test5,id: 13 , name: test6,.........If I have a list generated from user selection ( LIST{1, 7, 8, 15} ,) will I in a way be able to use this list in a query of the form, thus only having to make one query to the database: SELECT id, nameFROM Table1WHERE Table1.id in LIST Or is the solution to make multiple queries to the database, one for each member of the list, of the form:SELECT id, nameFROM Table1WHERE ID = @IDThanks in advance /dresen 

View 4 Replies View Related

Query List Of Datetimes For Same Date

Jul 7, 2007

Hi:I have created a table that has a column of smalldatetimes.  For any given day, there may be different records with the same date but with different times.  I've created the query SELECT Event FROM Events where Start=@Start and I input start as a selected date from the calendar control.  Because of the different times, I do not get any matches.   Could someone help me with a query that will get all of the events on the same day? Regards,Roger 

View 2 Replies View Related

SQL Query Linked To Drop Down List

Jan 20, 2008

I have a drop down list populated using sqldatasource1 it is populated with [item]
However, I need it to be poplulated with the three fields below AND, I don't want duplicates.  
SELECT [Item], [Alias1], [Alias2] FROM [Authors]
 

View 6 Replies View Related

Query To Get List Of Tables From Database

Sep 21, 2004

Can some one please tell me whats a best way ot get a list of all the tables that are present in a particular database.
Thanks

View 1 Replies View Related

Query To List Indexes From A Table ?

Sep 1, 2006

How can I list indexes with a (SQL) query ?
Thanks

View 1 Replies View Related

SP Or Query To List Locks Or Deadlocks ?

Sep 18, 2006

What could be the query or the stored procedure to list locks or deadlocks ?


Thanks

View 2 Replies View Related

Query List Of All Tables In A Database

Mar 5, 2014

I'm running SQL Server 2012 Express. I need to query a database and return the list of tables in the database. How to construct this query?

View 4 Replies View Related

Parameterized Query For A List Of Items

Sep 2, 2014

I am doing parameterized queries from Visual Basic in Visual Studio.

I have a query where I want to do something like this.

Select * from people where city in (<list of cities>)

The problem is I want to build my <list of cities> in Visual Basic and pass it to the SQL as a parameter.

I know I can't do this:

Select * from people where city in (@ListOfCities)

Currently, I'm doing this by writing the <list of cities> out to a separate table, just so I can do the query.

Select * from people where city in (Select CityName from CityTable)

View 4 Replies View Related

List Items From A Form Query

Feb 24, 2008

Hi,
I am a newbie, this is my first post (please go easy).

Iam at the moment trying to set up a query for someone looking for a property on an estate agents website.

From a drop down menu, the user can:
select an area (where they may like to live) from a list of areas.
select an amount of bedrooms from a list of bedrooms
select a minimum price from a list of prices
select a maximum price from a list of prices.

The query I worked out for this is as follows:
$data = mysql_query("SELECT * FROM property WHERE area like '$area' and bedrooms like '$bedrooms' AND price BETWEEN '$min_price' AND '$max_price'") or die(mysql_error());

This seems to work fine and shows all the properties that meet the criteria onto my webpage.

However, I then thought, someone may not care which area they live in and want to see all properties in all the areas, so I decided to add the option 'All areas' to my 'areas' list, I then did the same for the other lists, eg 'all bedrooms' option to my bedrooms list and so on.

I am now trying to write a query that incorporates where the 'all..' option is selected and have become very stuck!
Can someone set me off in the right direction for this.
I hope that makes sense?!?!

View 20 Replies View Related

Transact SQL :: Query To Get DB List And Size

Nov 19, 2015

I need to retrieve list of all databases and the size occupied by them in sql server. As of now am pulling data for each database using sys.dqatabase_files which is hard for me as there are around 40-50 db on SQL Server.

View 4 Replies View Related

How To Query A Sharepoint List From SSIS

Jan 2, 2008

I have been searching for a GOOD example of using SSIS to query MOSS 2007 list data. I just want to return the data from a list in Sharepoint and use that data in SSIS. It should be as simple as defining a data source to connect to a specific list and return the rows like a SQL query.

Can anyone provide a good example of doing this in SSIS (and by the way, I'm not looking for how to write a C# program) - I want to be able to do this directly from SSIS.

Any help would be greatly appreciated.

View 4 Replies View Related

SharePoint Query On List - RsCompilerErrorInExpression

Aug 14, 2007

I have been working on this all day. First day using SQL Reporting Services.

Software being used -

VS2005 - SQLServer Business Intelligence Studio - with SharePoint Windows Services 2.0 Web Services

1. I have created a Data Source - XML - Which is a SharePoint List

http://xxx.xxx.com/sites/OpRiskSP/OpRiskTechPM/MMUpdate07/_vti_bin/lists.asmx

Passed

2. Next I go to create a DataSet - ds

<Query>
<Method Namespace="http://schemas.microsoft.com/sharepoint/soap/" Name="GetListItems"/> <SoapAction>http://schemas.microsoft.com/sharepoint/soap/GetListItems</SoapAction>
</Query>


Parameters
1. Name = listName, Value = MaturityModelWorkingCopy

Next I Run the query and boom the data returns
Then I click the refresh button to populate the Reprots Datasets - called ds

Passed

3. Layout

I am assuming you can drag and drop the data fields onto the designer which that does work
I drag the first dataField and I get a textbox =

=First(Fields!ows_ID.Value)

Not sure what the First stands for

4. Preview

FAILED


[rsCompilerErrorInExpression] The Value expression for the query parameter €˜listName€™ contains an error: [BC30451] Name 'MaturityModelWorkingCopy' is not declared.

Build complete -- 1 errors, 0 warnings

Any help would be grand.

<moojjoo />







View 5 Replies View Related

How Will I Create A Delimited List In A SELECT Query?

Jun 10, 2007

SELECT FriendName from Friends where RegionId = 23
I would like to create a comma delimited list of 'FriendName' column values in above query (example - Mike,John,Lisa,Emburey).
How would I do that?

View 5 Replies View Related

MSSQL Query To List Out Unique Records

May 22, 2008

 hilet me explain my need..following are the tables im using..tbl_company (company table - parent)    id    company    1    test    2    test123    tbl_dept (department table - master)    id    dept    1    dept1    2    dept2tbl_compdept (company departments table - child)    cmpid    deptid    1            1    2            1    2            2    wats my need is.. while the company is listing..by query using joins, result was like this..company        depttest                dept1test123           dept1test123           dept2i need company test123 should be listd only once..when i use group by or distinct means, all r listed..is there any way to filter out therepeating company list by just listing the company list only once..

View 5 Replies View Related

Build SQL Query From Dynamic Checkbox List

Nov 26, 2003

Not sure if this is the place to post this, but here goes.

I need to setup an options screen where my customers can customize which locations will be stored for their user id when pulling reports. I have checkbox list that dynamically loads their locations. I need to store the selected checkbox items in my table and then each time they login in to run a report, it will use the stored Location values in my SQL query.

Synopsis:
Selected locations stored in table. When the report is ran, the location values are pulled and added to my queries WHERE clause.

Thanks.

View 1 Replies View Related

Dynamically Inserting A List In WHERE Clause Of A Query

Jul 8, 2014

What I need?: A way of dynamically inserting a list in the WHERE clause of a query. (in the form, WHERE ID = 1,2,3,6,9 etc)

Imagine an example DB with 3 columns Student ID, Name, Teacher_ID. (Lets assume Teacher_ID with value 100 means its the Headmaster)

I need to create a list with Student ID's, who are directly/indirectly under the Headmaster. Example:

Headmaster
Teacher 1 (ID 200)
Teacher 2 (ID 250)
Student 1 (ID 300)
Director
Teacher 4
Student 5

In the above example, since I only want those students/teachers under the headmaster, either directly/indirectly, my list would contain Teacher 1, Teacher 2, and Student 1. (In my case, just their ID's, so 200, 250, 300)

Director, Teacher 4 and Teacher 5 wouldnt be in the list since theyre not directly/indirectly Headmaster.

View 2 Replies View Related

T-SQL (SS2K8) :: Query To List Rows Into Columns?

Aug 10, 2015

I have requirement to list each row into column. I have tried with pivot query but unable to get it. I am using SQL Server 2008 database.

Here is the sample data:

CREATE TABLE dbo.test (
action_id numeric,
action VARCHAR(20) NOT NULL,

[Code].....

View 3 Replies View Related

Query Result As Comma-separated List

Jul 23, 2005

Hi,I'n in an environment where I cannot make stored procedures. Now I needto make a query with a subquery in the SELECT part which gives a commaseparated list of results:SELECTp.id,listFunction(SELECT name FROM names WHERE name_parent=p.id) AS'nameList'FROM projects AS pThis query should return something like:1, "john,mike,petra"2, "bob,carl,sandra,peter,etclistFunction is (of course) not (yet) defined. Is this possible withoutthe use of stored procedures?Mike

View 12 Replies View Related

Analysis :: How To Get List Of Attributes Involved In Particular MDX Query

Aug 3, 2015

I have a list of mdx queries extracted by sql server trace file. I want to get list of attributes and measures involved in each query.

View 6 Replies View Related

Transact SQL :: Query To Get List Of Permutation And Combinations

Aug 27, 2015

Below query:

Declare @table table
(
consumerID varchar(10),
customerNumber varchar(10)
)

Insert into @table
Select 1,123
union all

[Code] ...

--Expected output concatenation of consumer numbers all permutation and combinations having same

customernumber
1 2
1 3
1 4
2 3
2 4
3 4
5 6
5 7
6 7

View 4 Replies View Related

Function For Return Element List From A Query

Aug 9, 2007

Hello,

I have do a sql function for return a list of element from a query send in variable.



When I test the function on self I have no problem.

But when I use the function in a sql query I have problem.

example :




Code SnippetSELECT APPLI_SUPPLIER.N_SUPPLIER_ID, APPLI_SUPPLIER.V_SUPPLIER_LABEL,
dbo.APPLI_RETURN_LIST_ITEM('SELECT DISTINCT APPLI_CONSTRUCTION.V_PROCESS_CODE FROM APPLI_CONSTRUCTION INNER JOIN APPLI_SUPPLIER_SKILL ON APPLI_CONSTRUCTION.N_SUPPLIER_ID = APPLI_SUPPLIER_SKILL.N_SUPPLIER_ID WHERE (APPLI_CONSTRUCTION.V_PROCESS_CODE IS NOT NULL) AND (APPLI_SUPPLIER_SKILL.N_SKILL_ID IN (2,3,4,5,6))')
AS V_PROCESS_ITEMS
FROM APPLI_SUPPLIER INNER JOIN
APPLI_SUPPLIER_SKILL ON APPLI_SUPPLIER.N_SUPPLIER_ID = APPLI_SUPPLIER_SKILL.N_SUPPLIER_ID
WHERE (APPLI_SUPPLIER_SKILL.N_SKILL_ID IN (2, 3, 4, 5, 6))






This is the error :

Server: Msg 557, Level 16, State 2, Procedure APPLI_RETURN_LIST_ITEM, Line 24
Only functions and extended stored procedures can be executed from within a function.



When I do an exec of the function I have this problem :



Code Snippet
exec APPLI_RETURN_LIST_ITEM('SELECT DISTINCT APPLI_CONSTRUCTION.V_PROCESS_CODE FROM APPLI_CONSTRUCTION INNER JOIN APPLI_SUPPLIER_SKILL ON APPLI_CONSTRUCTION.N_SUPPLIER_ID = APPLI_SUPPLIER_SKILL.N_SUPPLIER_ID WHERE (APPLI_CONSTRUCTION.V_PROCESS_CODE IS NOT NULL) AND (APPLI_SUPPLIER_SKILL.N_SKILL_ID IN (2,3,4,5,6))')


Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near 'SELECT DISTINCT APPLI_CONSTRUCTION.V_PROCESS_CODE FROM APPLI_CONSTRUCTION INNER JOIN APPLI_SUPPLIER_SKILL ON APPLI_CONSTRUCTION.N_SUPPLIER_ID = APPLI_SUPPLIER_SKILL.N_SUPPLIER_ID WHERE (APPLI_CONSTRUCTION.V_PROCESS_CODE IS NOT NULL) AND (APPLI_SUPPLIER_SKILL.N_SKILL_ID IN (2,3,4,5,6))'



This is the function



Code Snippet
CREATE FUNCTION [dbo].[APPLI_RETURN_LIST_ITEM]
(@QUERY AS VARCHAR(3900)=null)
RETURNS varchar(8000)
AS
BEGIN
-- Insert statements for procedure here
declare @v_List_ITEM as varchar(8000)
set @v_List_ITEM=''
if @QUERY is not null
Begin
declare @cur_Lect_ITEM CURSOR;
declare @FUNCTION AS NVARCHAR(4000);
Declare @ITEM as VARCHAR(255);
SET @FUNCTION = 'set @mainCursor=cursor for ' + @QUERY + ' for read only open @mainCursor'


EXEC sp_executesql @FUNCTION,N'@mainCursor cursor output', @cur_Lect_ITEM output
fetch next from @cur_Lect_ITEM into @ITEM
while @@fetch_status=0
begin
set @v_List_ITEM=@ITEM + ' ; ' + @v_List_ITEM
fetch next from @cur_Lect_ITEM into @ITEM
end
deallocate @cur_Lect_ITEM
SET @v_List_ITEM=REPLACE(REPLACE(@v_List_ITEM, CHAR(13), ''), CHAR(10), '')
set @v_List_ITEM=left(@v_List_ITEM,len(@v_List_ITEM)-3)
End
RETURN @v_List_ITEM
END


Can you help me please?
Thank you

View 11 Replies View Related

How Do I List Contents Of File Directory In The SQL Query Analyzer

Apr 13, 2006

how do I list contents of file directory in the SQL Query Analyzer

View 1 Replies View Related

Query To Create A Countable List Using A Single Value From Table

Mar 15, 2004

Hi,

from a single numeric value, say 'n', in a field in a table, i'd like to create a SELECT query that produces a list from 1 to n, e.g

if the value was 6, I would like selected back:
1
2
3
4
5
6

Any pointers?
Greg

View 5 Replies View Related

SQL Server 2012 :: Query From A List In Excel File

Feb 11, 2014

I have database tables for

Stores
StoreId, Name

Products
ProductId, Name

Transactions
TransactionId, StoreId, ProductId

I was just given an excel file with a list of 300 Stores.

I need to find out if these stores are selling our products and if they are , how many products they are selling.

One way of doing this , that I can think of right now is individually querying the Transactions table for each of the store in the excel sheet and then copy the results output back to the excel sheet.

Is there a way I can write a query against all the Store names from the excel file ? I need to get this done in the next few hours.

View 9 Replies View Related

SQL Server 2012 :: Query To List Win / Loss Streaks

Nov 5, 2014

I have a Games table in a SQL Server 2012 database with game results from our league, including home and away scores, dates, and teams. How can I query to list streaks - that is, wins or losses of 2 more games in a row throughout a season?

View 6 Replies View Related







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