I need to performance tune following SQL query by removing "OR" statements
Please help ...
SELECT a.id, a.fileType, a.uploadTime, a.filename, a.userId, a.CID, ui.username, company.name companyName, a.screenName
FROM TM_transactionLog a, TM_userInfo ui, TM_company company, TM_airlineCompany ac
WHERE
(
a.CID = 3049
)
OR
(
a.CID = company.ID
AND
ac.SERVICECID = 3049
AND
company.SPECIFICCID = ac.ID
)
OR
(
a.USERID = ui.ID
AND
ui.CID = 3049
);
I want to use infinite WHILE loop in SQL 2005 and use BREAK keyword to exit from it on certain condition.
while true does not work, so I have to use while 1=1.
Is there a better way to organize infinite loop ?
I know that I can use goto, but while 1=1 begin .. end looks better structurally.
I have a table; let it be called table1; with the following fields and data
I need a query that returns the record with the maximum value in Field3 for each group of records having the same value in Field2. So that the query returns:
How could this be done using SQL queries ?
Is there a way to get the profiler without installing Microsoft Sql Server?
If the answer is no, which edition do I need to get the profiler? Do I need the Developer Edition?
I have an Oracle SQL query as part of a stored proc:
DELETE FROM item i WHERE NOT EXISTS (SELECT 1 FROM item_queue q WHERE q.n=i.n) AND NOT EXISTS (SELECT 1 FROM tool_queue t WHERE t.n=i.n);
A bit about the tables:
item contains about 10k rows with an index on the n column
item_queue contains about 1mil rows also with index on n column
tool_queue contains about 5mil rows indexed as well
I am wondering if the query/subqueries can be optimized somehow to make them run faster, I thought that deletes were generally fairly fast
I have a table for animals like
Lion
Tiger
Elephant
Jaguar
List item
Cheetah
Puma
Rhino
I want to insert new animals in this table and I am t reading the animal names from a CSV file.
Suppose I got following names in the file
Lion,Tiger,Jaguar
as these animals are already in "Animals" table, What should be a single SQL query that will determine if the animals are already exist in the table.
I use SQL Server 2000.
Suppose I have two tables like the following:
Area
----------------------------------
ID| Name | HierarchyLevel
----------------------------------
1 | World | 1
2 | America| 2
3 | Europe | 2
4 | Africa | 2
5 | USA | 3
and
AreaHierarchy
------------------------
ID | ParentID | ChildID
------------------------
1 | 1 | 2
2 | 1 | 3
3 | 1 | 4
4 | 2 | 5
where
AreaHierarchy.ParentID and AreaHierarchy.ChildID are FKs of Area.ID
How can I find the nth parent of USA?
Is it possible without looping?
Probably not.
For example, imagine that I want to see if a user exists in my database:
Select * from Users where inputID = Users.ID
Then if that result brought 0 items, then the user exists, correct?
How can I do something like this using a pure Linq-to-SQL class?
I am trying to write a sql query like the example below, however, I need it to always choose the DateEntered field between the current day's date at 8:00am and the current day's date at 4:00pm. Not sure how to go about this. Can someone please help?
SELECT OrderNumber
, OrderRelease
, HeatNumber
, HeatSuffix
, Operation
, COUNT(Operation) AS [Pieces Out of Tolerance]
FROM Alerts
WHERE (Mill = 3)
AND (DateEntered BETWEEN GetDate '08:00' AND GetDate '16:00')
GROUP BY OrderNumber, OrderRelease, HeatNumber, HeatSuffix, Operation
I am trying to insert NULL value in Sql Server if I have null value in corresponding C# String object like below :
String Residence = xmlDoc.Descendants("Appointment").Single().Element("StateOfResidence") == null ? null : xmlDoc.Descendants("Appointment").Elements("StateOfResidence").Single().Value;
I am using Entity framework for Database access. So if Residence is null, 'NULL' gets inserted into Database instead of NULL. How can insert NULL for null ?
I have a SQL Server 2012 Sequence object:
/****** Create Sequence Object ******/
CREATE SEQUENCE TestSeq
START WITH 1
INCREMENT BY 1;
I have a SP that runs some queries inside a transaction:
BEGIN TRAN
SELECT NEXT VALUE FOR dbo.TestSeq
<here all the query update code......>
ROLLBACK TRAN
If the transaction fails all the updates are rolledback without problem but the Sequence is not rolled back I guess because Its out of the scope of the transaction.
Any clue on way to handle that?
Thanks
With windows and sql server accounts, I can access the logged in user with functions like: user_name() or suser_sname().
Can I access the user that is logged into asp.net in the same way?
Is it possible to create a table which has a check constraint on one of the column whose value lies within the result set given by another sql query
eg.
create table tablename
(
name varchar(10),
rollno int
)check rollno in (select rollno from anotherDatabase.TableName,candidateRoll)
or any thing like that.
I dont have to use it anywhere but still want to know.
Hello Guys!
I've two MS SQL tables: Category, Question. Each Question is assigned to exactly one Category. One Category may have many subcategories.
Category
Id : bigint (PK)
Name : nvarchar(255)
AcceptQuestions : bit
IdParent : bigint (FK)
Question
Id : bigint (PK)
Title : nvarchar(255)
...
IdCategory : bigint (FK)
How do I recursively count all Questions for a given Category (including questions in subcategories). I've tried it already based on several tutorials but still can't figure it out :(
I've got a column in a SQL Server table that is type XML. I want to change multiple values in the XML in a stored proc. I've already found the XML.Modify(...) command and have it working for a single value. Can I change multiple values in the XML in one update command or do I need to do it as multuple update commands?
I need to make DISTRIBUTED TRANSACTION between two MS SQL Server 2005,
it drops an error that NO ACTIVE TRANSACTION IS PRESENT or smth like this.
DTCTESTER programs drops an error that transaction could not be done.
btw 135 port is open on the firewall.
Maybe anyone knows what a problem, or have a suggestion?
i am using sql server 2005, please tell me how can i get 6 digits (unique numeric which should be random) value for every row in table.
i have a field in table in which i needs 6 digit numeric value (random and unique).
please help me to do this.
In VS2005, I am using a DLL which accesses a SQL Server. The DLL returns a SQLException
Invalid object name 'tableXYZ'
but tableXYZ is a table in the database.
Should it be looking for dbo.tableXYZ instead? Is this a permissions issue with the login being used?
i m using SQL Server 2008 R2.
i want to update my column CODE_DEST with increment number
CODE_DEST RS_NOM
null qsdf
null sdfqsdfqsdf
null qsdfqsdf
what i want:
CODE_DEST RS_NOM
1 qsdf
2 sdfqsdfqsdf
3 qsdfqsdf
i have try this:
update DESTINATAIRE_TEMP
set CODE_DEST = TheId FROM (SELECT Row_Number() OVER (ORDER BY [RS_NOM]) as TheId from DESTINATAIRE_TEMP)
not work because of )
and this
With DESTINATAIRE_TEMP As
(
SELECT
ROW_NUMBER() OVER (ORDER BY [RS_NOM] DESC) AS RN
FROM DESTINATAIRE_TEMP
)
UPDATE DESTINATAIRE_TEMP SET CODE_DEST=RN
because of union
im trying to work through some questions and im not sure how to do the following
Q:Find the hard drive sizes that are equal among two or more PCs.
its q15 on this site
http://www.sql-ex.ru/learn_exercises.php#answer_ref
The database scheme consists of four tables:
Product(maker, model, type)
PC(code, model, speed, ram, hd, cd, price)
Laptop(code, model, speed, ram, hd, screen, price)
Printer(code, model, color, type, price)
any pointers would be appreciated.
In SQL Server, it is possible to test the result of a stored procedure to know if the result return rows or nothing ?
Example :
EXEC _sp_MySp 1, 2, 3
IF @@ROWCOUNT = 0
BEGIN
PRINT('Empty')
END
ELSE
BEGIN
PRINT(@@ROWCOUNT)
END
But @@ROWCOUNT always return 0 so maybe is there another way of doing this ?
Hello Guys!
I've two MS SQL tables: Category, Question. Each Question is assigned to exactly one Category. One Category may have many subcategories.
Category
Id : bigint (PK)
Name : nvarchar(255)
AcceptQuestions : bit
IdParent : bigint (FK)
Question
Id : bigint (PK)
Title : nvarchar(255)
...
IdCategory : bigint (FK)
How do I recursively count all Questions for a given Category (including questions in subcategories). I've tried it already based on several tutorials but still can't figure it out :(
How to make an SQL query if there are 30 records in table and I want to pick rows from 12 to 20 where 12 and 20 are row numbers not Ids.
**Ids Code**
5 ABC
6 SDF
8 WSA
10 FSD
15 IOP
.
.
.
.
80 AWS
Not sure what's happening with this, but here's my question. I have a Sql Server 2008 database that I need to be able to do full-text indexing/searching but when I try to setup my indices on the table, I get the following:
I've tried running this stored procedure on my database and it's successful:
EXEC sp_fulltext_database @action = 'enable'
But I still get the above window and my full-text searches don't return any results when they should.
What am I missing?