I am trying to get better information on deadlocks that are occurring in my DB. After reading this article, it's still unclear to me whether I should be using trace flag 1204, 1222 or both.
Hello,
I have a loop that runs for approx. 25 minutes i.e 1500 seconds. [100 loops with sleep(15)]
The execution time for the statements inside loop is very less.
My scripts are hosted on GoDaddy. I am sure that they are having some kind of limit on execution time.
My question is, are they concerned with "the total CPU execution time" or the total running time.
Hi,
I've got table Articles
ID identity autoincement, IDArticle: nvarchar(100) ,IDCar nvarchar(100), createddate
How to convert this:
SELECT IDCar , MAX(createddate)
FROM Articles
GROUP BY IDCar
to get IDArticle
eg:
1 art1 BWM 5-21-2010
2 art2 BMW 5-24-2010
3 art3 BMW 5-31-2010
4 art4 Porshe 5-31-2010
5 art5 Porshe 6-1-2010
Expecting result is:
art3
art5
It's not duplicated with:
http://stackoverflow.com/questions/2736769/sql-query-number-of-occurance/2736809#2736809
Table subscribe
subscriber | subscribeto (columns)
1 | 5
1 | 6
1 | 7
1 | 8
1 | 9
1 | 10
2 | 5
2 | 6
2 | 7
There are two users that have id 1 and 2. They subscribe to various user and I inserted these data to table subscribe. Column subscriber indicates who is subscriber and column subscribeto indicates who they've subscribe to. From the above table can conclude that; user id=1 subscribed to 6 users
user id=2 subscribed to 3 users
I want to find manual of subscription (like Facebook is manual friends)
user 1 subscribe to user 5,6,7,8,9,10
user 2 subscribe to user 5,6,7
So, Manual subscription of user 1 and 2 are: 5,6,7
And I'm trying to create SQL statement..
I give you user table for my SQL statement and I think we can use only subscribe table but I can't figure out.
Table user
userid (columns)
1
2
3
...
...
SQL
"select * from user where (select count( 1 ) from subscribe where subscriber = '1' and subscribeto = user.userid) and (select count( 1 ) from subscribe where subscriber = '2' and subscribeto = user.userid);"
This SQL can work correctly, but it very slow for thousands of columns. Please provide better SQL for me, Thanks.
I'd like to have a query returning two ResultSets each of which holding exactly half of all records matching a certain criteria. I tried using TOP 50 PERCENT in conjunction with an Order By but if the number of records in the table is odd, one record will show up in both resultsets. Example:
I've got a simple table with TheID (PK) and TheValue fields (varchar(10)) and 5 records. Skip the where clause for now.
SELECT TOP 50 PERCENT * FROM TheTable ORDER BY TheID asc
results in the selected id's 1,2,3
SELECT TOP 50 PERCENT * FROM TheTable ORDER BY TheID desc
results in the selected id's 3,4,5
3 is a dup. In real life of course the queries are fairly complicated with a ton of where clauses and subqueries.
I have a WCF service running over MSMQ. Memory gradually increases over time, indicating that there is some sort of memory leak. I ran the service locally and monitored some counters using PerfMon. Total CLR memory managed heap bytes remains relatively constant, while the process' private bytes increases over time. This leads me to believe that there is some sort of unmanaged memory leak. Assuming that unmanaged memory leak is the issue, how do I address the issue? Are there any tools I could use to give me hints as to what is causing the unmanaged memory leak? Also, all my service is doing is reading from the transactional queue and writing to a database, all as part of a DTC transaction (handled under the hood by requiring a transaction on the service contract). I am not doing anything explicitly with COM or DllImports.
Thanks in advance!
Hi ,
I have column which consists of path for example \Abc\F\E\record_123 , now i need to update the path in database where only one change i need to do is tht
\Abc\F\E\record_123 = \Abc\F\G\record_123 - i want to update E to G .
how to do that with update query in database .
Can anyone help me its urgent.
Thanks
Smartdev
I need help please with writing a sproc, it takes a table-valued parameter @Locations, whose Type is defined as follows:
CREATE TYPE [dbo].[tvpLocation] AS TABLE(
[CountryId] [int] NULL,
[ResortName] [nvarchar](100) NULL,
[Ordinal] [int] NOT NULL,
PRIMARY KEY CLUSTERED
(
[Ordinal] ASC
)WITH (IGNORE_DUP_KEY = OFF)
)
@Locations will contain at least 1 row. Each row WILL have a non-null CountryId, and MAY have a non-null ResortName.
Each row will have a unique Ordinal, the first being 0. The combinations of CountryId and ResortName in @Locations will be unique.
The sproc needs to search against the following table structure.
The image can be seen better by right-clicking it and View Image, or similar depending on your browser.
Now this is where I'm stuck, the sproc should be able to find Tours where:
The Tour's 1st TourHotel (Ordinal 0)
has the same CountryId (and ResortName
if specified) of the 1st row of
@Locations (Ordinal 0).
And also if @Locations has 1 row,
the Tour must have additional
TourHotels, ALL of which must be in the
remaining CountryIds (and ResortNames if specified) of these remaining @Locations rows.
Edit This is the code I finally used, based on Anthony Faull's suggestion. Thank you so much Anthony:
select distinct T.Id
from tblTour T
join tblTourHotel TH on TH.TourId = T.Id
join tblHotel H ON H.Id = TH.HotelId
JOIN @Locations L ON
(
(
L.Ordinal = 0
AND TH.Ordinal = 0
)
OR
(
L.Ordinal > 0
AND TH.Ordinal > 0
)
)
AND L.CountryId = H.CountryId
AND
(
L.ResortName = H.ResortName
OR L.ResortName IS NULL
)
cross apply( select COUNT(TH2.Id) AS [Count] FROM tblTourHotel TH2 where TH2.TourId = TH.TourId ) TourHotelCount
where
TourHotelCount.[Count] = @LocationCount
group by T.Id, T.TourRef, T.Description, T.DepartureDate, T.NumNights, T.DepartureAirportId, T.DestinationAirportId, T.AirlineId, T.FEPrice
having COUNT(distinct TH.Id) = @LocationCount
I'm wondering if anyone is currently utilizing Microsoft's Master Data Services? How you are utilizing it? Whether you find it useful? When you believe it would be useful? Thanks!
Here is my Query... Here I'm using a function Fn_getStagesForProject()... For which I need to pass the SWProjectID from Projects Table...
The function takes the ID as parameter and return all stages that corressponds to the project, on which I need to filer only the row that contains StageLevel as 0.
Select A.SWProjectID,
A.ShortTitle,
C.StageName as StageName,
B.ExpectedCompletionDate as BudgetedReleaseDate
From Projects as A
left outer join ProjectBudgets as B on A.SWProjectID = B.SWProjectID
Left outer join Fn_getStagesForProject(Projects.SWProjectID) as C on B.StageID = C.StageID
Where C.StageLevel = 0
The error is
The multi-part identifier "Projects.SWProjectID" could not be bound.
I tried changing it to A.SWProjectID, but I still get the error...
Thanks in advance for your help. Let me know, incase you need the Table Structure
Raja
I am currently building my own CMS for various reasons that could take a long to explain...
However i am looking for a dynamic solution to create templates for pages within the CMS and all areas must be editable via the administration area, maybe large text areas broken into multiple areas, text and image area on a page etc.
Following on from the above i would like to create the following:
Create a new page (selecting a pre-defined template like below)
http://img525.imageshack.us/img525/9872/nestedpages.png
and then upon editing the page it would have created as many text editors required for each editable region or a file upload control for an image area for example.
i am thinking of using nested masterpages for the design elements, just unsure the best-practice way to achieve the above (db structure etc)
I somehow hope this provides enough information but are happy to answer any questions you may have.
Thanks
I need to be able to check if a variable has a certain string of text inside it. Here's what I have now:
--This sample always goes to the ELSE block.
IF( @name LIKE '%John%' )
BEGIN
--do one thing
END
ELSE
BEGIN
--do the other thing
END
select @[email protected]('*')
for xml raw,type
Above statement will generate following alert:
Msg 6819, Level 16, State 3, Line 2
The FOR XML clause is not allowed in a ASSIGNMENT statement.
Hi,
I've got some excel files, that were exported from tables in Access, and I want to import them into sql express 2005.
I need a script that will convert nvarchar(255) columns to varchar(255) and preserve links, when importing the data into sql express.
Thanks
hi all,
I have a db with users that have all this record .
I would like to do a query on a data like
CN=aaa, OU=Domain,OU=User, OU=bbbbbb,OU=Department, OU=cccc, OU=AUTO, DC=dddddd, DC=com
and I need to group all users by the same ou=department.
How can I do the select with the substring to search a department??
My idea for the solution is to create another table that is like this:
---------------------------------------------------
ldapstring | society | site
---------------------------------------------------
"CN=aaa, OU=Domain,OU=User, OU=bbbbbb,OU=Department, OU=cccc, OU=AUTO, DC=dddddd, DC=com" | societyName1 | societySite1
and my idea is to compare the string with these on the new table with the tag like but how can I take the society and site when the like string occurs?????
Please help me
I am having a small problem trying to decide on database schema for a current project. I am by no means a DBA.
The application parses through a file based on user input and enters that data in the database. The number of fields that can be parsed is between 1 and 42 at the current moment.
The current design of the database is entirely flat with there being 42 columns; some have repeated columns such as address1, address2, address3, etc...
This says that I should normalize the data. However, data integrity is not needed at this moment and the way the data is shaped I'm looking at several joins. Not a bad thing but the data is still in a 1 to 1 relationship and I still see a lot of empty fields per row.
So my concerns are that this does not allow the database or the application to be very extendable. If they want to add more fields to be parsed (which they do) than I'd need to create another table and add another foreign key to the linking table.
The third option is I have a table where the fields are defined and a table for each record. So what I was thinking is to make a table that stores the value and then links to those two tables. The problem is I can picture the size of that table growing large depending on the input size. If someone gives me a file with 300,000 records than 300,000 x 40 = 12 million so I have some reservations. However I think if I get to that point than I should be happy it is being used. This option also allows for more custom displaying of information albeit a bit more work but little rework even if you add more fields.
So the problem boils down to:
1. Current design is a flat file which makes extending it hard and it is not normalized.
2. Normalize the tables although no real benefits for the moment but requirements change.
3. Normalize it down into the name value pair and hope size doesn't hurt.
There are a large number of inserts, updates, and selects against that table. So performance is a worry but I believe the saying is design now, performance testing later?
I'm probably just missing something practical so any comments would be appreciated even if it’s a quick sanity check.
Thank you for your time.
Why does
left(FIELD, replace(nullif(charindex('-', FIELD), 0), null, len(FIELD)))
always return null? The idea behind the query is that if charindex() returns 0, then convert the results into null, then convert the null into the length of the field. So if '-' does not exist, show the whole string. For some reason it makes every row equal null.
Thank you.
I have a large historical transaction table (15-20 million rows MANY columns) and a table with one row one column. The table with one row contains a date (last processing date) which will be used to pull the data in the trasaction table ('process_date').
Question: Should I inner join the 'process_date' table to the transaction table or the transaction table to the 'process_date' table?
i tried something like this but the id value is not changing, getting the value for first record and set the value for all rest...
insert into table1 (Id,b,c,d)
(select (select max(Id)+1 from table1),x,y,z from table2 where... )
I'm trying to build a simple sql database for following access database. Currently there is no relationship and I just have two tables male and female with 6 sections in each form. How can I design it a better way so end user can connect to the database and analyze using STATA or SPSS ?
I'm really confused whether I should create one table with all fields or break down into different tables. The database is specific to this study only so I'm not looking for a generic survey database where user can create surveys and capture them. Any feedback or suggestion is much appreciated.
I have a table with a lot of columns. For example I have a table with these columns :
ID,Fname,Lname,Tel,Mob,Email,Job,Code,Company,......
ID column is auto number column. I want to copy all rows in this table to this table and change the company column value to 12 in this copied row. I don't want to write name all of the columns because I have a lot of table with a lot of columns.
I tried this code but I had this error :
declare @c int;
declare @i int;
select * into CmDet from CmDet;
select @C= count(id) from CmDet;
while @i < @C
begin
UPDATE CmDet
SET company =12
WHERE company=11
set @i += 1
end
error :
Msg 2714, Level 16, State 6, Line 3
There is already an object named 'CmDet' in the database.
I changed the code to this
declare @c int
declare @i int
insert into CmDet select * from CmDet;
select @C= count(id) from CmDet;
while @i < @C
begin
UPDATE CmDet
SET company =12
WHERE company=11
set @i += 1
end
and I had this error :
Msg 8101, Level 16, State 1, Line 3 An explicit value for the
identity column in table 'CmDet' can only be specified when a column
list is used and IDENTITY_INSERT is ON.
What should I do ?
Hi,
I have a table which have 6 million recods,when a fire select query with where condition in that table it is timing out.
How can I make it run, Please help
While trying to optimize SQL scripts, I was recommended to add indexes.
What is the easiest way to specify what Database the index should be on?
IF EXISTS (SELECT * FROM sysindexes WHERE NAME = 'idx_TableA')
DROP INDEX TableA.idx_TableA
IF EXISTS (SELECT * FROM sysindexes WHERE NAME = 'idx_TableB')
DROP INDEX TableB.idx_TableB
In the code aboce, TableA is in DB-A, and TableB is in DB-B.
I get the following error when I change DROP INDEX TableA.idx_TableA to DROP INDEX DB-A.dbo.TableA.idx_TableA
Msg 166, Level 15, State 1, Line 2
'DROP INDEX' does not allow specifying the database name as a prefix to the object name.
Any thoughts are appreciated.