How can i update bulk data in sqlserver 2005 by sending the data in XML form ?
i am able to insert bulk data into the table, but i am not getting idea to update the data.
What are those pro/subtle techniques that SQL provides and not many know about which also cut code and improve performance?
eg: I have just learned how to use CASE statements inside aggregate functions and it totally changed my approach on things.
Are there others?
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 am trying you insert some string which is not in English (other language). when i fetch back they are not correct. They comes like "?????".
But at the same time when I enter the string through the SQLServer UI (SSMS) to enter the string, it works OK.
What could be the solution please?
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 ?
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 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
);
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 would like to do something like this i.e., use wild card characters in the in clause:
SELECT * FROM mytable WHERE keywords IN ('%test%', '%testing%')
This is not supported in MS SQL.... Is there some other way to achieve it...
Looking for something other than:
SELECT * FROM mytable WHERE keywords like '%test%' or keywords like '%testing%' or.....
i am doing this:
CREATE TABLE person
(
num INT NOT NULL ,
firstname VARCHAR(20) NULL ,
lastname VARCHAR(30) NULL
);
sqlserver is just saying "debbuging" and it's not doing anything
is there a problem with the syntax or what?
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.
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 use SQLServer 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.
I am trying to insert NULL value in SqlServer 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 am getting the error from the application as following with SQLserver 2005
"Transaction count after EXECUTE
indicates that a COMMIT or ROLLBACK
TRANSACTION statement is missing.
Previous count = 1, current count =
0"
How can i find the stage where this error raised?
how can i found the missing transaction or the stored procedure where it is not committ or rollback?
I have a SQLServer 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
Suppose I have got a table which I have to insert the description of the contract under different keys of contract.
But when executing, there is a n error near then
Is there any limitation of using syntax set ?
The below is my SQL
declare @i int, @j v nvarchar(MAX)
set @i = 1
while (@i<=8)
begin
set @j = case when @i = 1 then 'CR' when @i = 2 then 'Facebook' else 'N/A' end
INSERT INTO CostNature (CNKey, CNNDescription) VALUES (@i , @j );
set @i = @i + 1
end
In PostgreSQL there is the Limit and Offset keywords which will allow very easy pagination of result sets. What is the equivalent syntax for Sql Server?
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 am using sqlserver 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.
I need to make DISTRIBUTED TRANSACTION between two MS SQLServer 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?
Hi,
I'm using SqlServer 2005 and i'm trying to achieve something like:
In the same select statement i want to get the first x rows and the last x rows.
SELECT TOP(5) BOTTOM(5)
Of course 'bottom' does not exist so i need other solution.
I believe there is an easy and elegant solution that i'm not getting.
Doing the select again with Group By Desc is not an option.
Thanks.
In VS2005, I am using a DLL which accesses a SQLServer. 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?