Showing posts with label running. Show all posts
Showing posts with label running. Show all posts

Friday, March 30, 2012

Help on this

Hello:

I am currently running a query and it is taking like 6 hours to run.

what I do is:

I loop through user's table (20000 users) using a cursor, for each user I call a stored procedure "EXEC ...", then in that called stored procedure, I have an a set of 6 IF statements, and in each if statement I have a call for a simple stored procedure,.

Can anyone tell me, how can i optimize that query?

thanks a lot

Don't use a cursor? We'd need to know more specifics about what it's actually doing to determine if you can do this as a set operation instead of row-by-row (cursor).

Marcie

|||

Hello Marcie:

Thank you for your reply.

I sent you an email from your Blog, it has some codes.

thanks a lot,

|||

Hi SNT2,

I don't have access to that email account during the day, sorry. Also, if you'll post the code here (or at least an overview of what it does), other people will be able to help you with your problem too.

Take care,

Marcie

|||

Hello, I will list the Stored Procedures here: As I said, there is a main procedure, which loops using a cursor through all the records, and upon getting each account I call a method, the first method is the general one:

CREATE PROCEDURE ActiveUserAnalysis_AnalyzeUsers( @.AnalysisPeriod int = 30, -- the number of days over which the refills are checked @.CustGrpId int = 101, -- the group that we want to analyze @.AnalysisId int out)ASBEGIN SET NOCOUNT ON --create the analysis record INSERT INTO ActiveUserAnalysis ( AnalysisTime, AnalysisPeriod, CustGrpId) VALUES ( getdate(), @.AnalysisPeriod, 101) SET @.AnalysisId = @.@.identityDECLARE @.UserCount int SET @.UserCount = 0 --loop over all active users and analyze them DECLARE cActiveCustomers CURSORREAD_ONLYFOR select customerid, username from activecustomersview where custgrpid=@.CustGrpIdDECLARE @.customerid intDECLARE @.username varchar(30)OPEN cActiveCustomersFETCH NEXT FROM cActiveCustomers INTO @.customerid, @.usernameWHILE (@.@.fetch_status <> -1)BEGINIF (@.@.fetch_status <> -2)BEGIN SET @.UserCount = @.UserCount + 1 EXEC ActiveUserAnalysis_AnalyzeActiveUser @.AnalysisId, @.AnalysisPeriod, @.CustomerId, @.UserName   ENDFETCH NEXT FROM cActiveCustomers INTO @.customerid, @.usernameENDCLOSE cActiveCustomersDEALLOCATE cActiveCustomers UPDATE ActiveUserAnalysis SET ActiveUserCount = @.UserCount WHERE AnalysisId = @.AnalysisId SELECT Classification, count(*) FROM ActiveUserAnalysis_Results WHERE AnalysisId = @.AnalysisId GROUP BY ClassificationENDGO


Now the method we are calling above for each user is:

CREATE procedure ActiveUserAnalysis_AnalyzeActiveUser( @.AnalysisId int, @.AnalysisPeriod int, @.customerid int, @.username varchar(30))asbegin DECLARE @.TokenType varchar(4) DECLARE @.Expires datetime DECLARE @.Value int DECLARE @.LastActivity datetime DECLARE @.RefillType varchar(30) DECLARE @.LastRefillDate datetime DECLARE @.RefillCount int DECLARE @.TBSUserName varchar(30) --First collect info EXEC ActiveUserAnalysis_GetUsageToken @.customerid, @.TokenType out, @.Value out, @.Expires out SELECT TOP 1 @.LastActivity = LastActivity FROM PPPAccount WHERE CustomerId = @.CustomerId --Classify user -- 1- Refill EXEC ActiveUserAnalysis_CheckUserLastRefills @.CustomerId, @.AnalysisPeriod, @.RefillType out, @.LastRefillDate out if @.@.rowcount > 0 BEGIN INSERT INTO ActiveUserAnalysis_Results (AnalysisId, customerid, classification, lastactivity, refilltype, lastrefilldate, tokentype, value, expires) VALUES (@.AnalysisId, @.customerid, 'Refill', @.LastActivity, @.RefillType, @.LastRefillDate, @.TokenType, @.Value, @.Expires) RETURN END -- 2- NoLogin: He hasn't logged in at all during period If datediff (d, @.LastActivity, getdate()) > @.AnalysisPeriod BEGIN INSERT INTO ActiveUserAnalysis_Results (AnalysisId, customerid, classification, lastactivity, refilltype, lastrefilldate, tokentype, value, expires) VALUES (@.AnalysisId, @.customerid, 'NoLogin', @.LastActivity, @.RefillType, @.LastRefillDate, @.TokenType, @.Value, @.Expires) RETURN END --3 Other. If we reached here, then the user does not fit with any of the above categories INSERT INTO ActiveUserAnalysis_Results (AnalysisId, customerid, classification, lastactivity, refilltype, lastrefilldate, tokentype, value, expires) VALUES (@.AnalysisId, @.customerid, 'Other', @.LastActivity, @.RefillType, @.LastRefillDate, @.TokenType, @.Value, @.Expires)ENDGO

I didn't include all cases, but i listed only 3 of them.

Then in every case I am calling a procedure too.

Can that be optimzed?

Thanks Marcie

|||

Yes, but it will take some significant work. You haven't included the stored procedures/views that this depends on, so I can't really give you code that will work 100%.

Start off by creating a view for many of the stored procedures that this thing depends on... Can you post the code for say...

ActiveUserAnalysis_CheckUserLastRefills? Hopefully that doesn't call any more stored procedures/views.

|||

Hello, thank you for helping me.

The SP is as follows:

CREATE procedure ActiveUserAnalysis_CheckUserLastRefills(@.CustomerId int,@.AnalysisPeriod int, -- in days,@.Refilltype char(5) out,@.LastRefillDate datetime out)asselect top 1 @.RefillType=c.ISKCatCode, @.LastRefillDate = datepurchasedfrom isk i inner join iskcategory c on i.iskcatid = c.iskcatidwhere customerid = @.customerid and datediff(d, datepurchased, getdate()) <= @.AnalysisPeriod and i.CreatedNewCustomer = 0order by datepurchased descGO

Thank you.|||

Hello Marcie:

Can you help in that please?

thanks

|||

SomeNewTricks2 wrote:

I am currently running a query and it is taking like 6 hours to run.

what I do is:

I loop through user's table (20000 users) using a cursor, foreach user I call a stored procedure "EXEC ...", then in that calledstored procedure, I have an a set of 6 IF statements, and in each ifstatement I have a call for a simple stored procedure,.

Can anyone tell me, how can i optimize that query?


That's an awful big haystack. Have you pinpointed thebottleneck? I'd suggest running the query from Query Analyzerwith Show Execution Plan turned on. This should give you an ideaof the slow parts.

Also, this will not likely make an appreciable difference in yourexecution time, but instead of a cursor I'd use a #temp table (see anexample of this approach in this post:http://forums.asp.net/511669/ShowPost.aspx).|||

SomeNewTricks2 wrote:

Hello Marcie:

Can you help in that please?

thanks

My gut feel is still that you could probably do all of this with one (large) Update statement, rather than looping through thousands of items and doing them one at a time. If that gets too complex (or is not possible), using a #temp table as Terri suggests will make this job easier, and much faster than the cursor approach.

Marcie

|||

Thank you all.

Do you think using a loop over a temp table, is better than cursor?

What about the "if" statements, is using them ok?

thanks

|||

SomeNewTricks2 wrote:

Do you think using a loop over a temp table, is better than cursor?


Yes I do, that's why I suggested it. Here's a little background information:SQL Server Temp Table Performance.

SomeNewTricks2 wrote:

What about the "if" statements, is using them ok?


I think using them is OK, but as far as I understand it, when SQLServer compiles the stored procedure it will use the execution planbased on whichever parameters were passed to it the first timethrough. So the execution plan may not be optimized for otherparameters. But I have also read that SQL Server often recompilesstored procedures, so I don't know how much of an issue that truly is.

Again, I urge you to identifiy your bottleneck(s). You havepresented a huge haystack to look through, and it could be that onesmall part needing optimization is causing all of the performanceissues. We don't really have enough information to be able tohelp you.

|||

Sorry, been away for a few days... I didn't see that you were stuffing some of values from ActiveUserAnalysis_GetUsageToken in your inserts, could you post that code? As long as it's pretty simple, I'll have some working code for ya that should be magnitudes faster than what you are currently doing by using set-based rather than cursor-if based logic.

Cursoring over a temp table won't be faster than cursoring over a query, however, you will have less transaction collisions (possibly). The article the above poster referenced, is saying temp tables are faster if by using one you can avoid a cursor and use set-based logic, which is what you'll probably have to do, but possibly not, but it doesn't eliminate the need to move away from the cursor-if logic.

|||

First of all, thank you Terri for your help.

Here is the code:

create procedure ActiveUserAnalysis_GetUsageToken
(
@.customerid int,
@.TokenType varchar(4) out,
@.Value int out,
@.Expires datetime out
)
as
SELECT TOP 1 /* get only first (highest priority) token */
@.TokenType=t.TokenTypeId, @.Value=u.Value, @.Expires=u.Expires
FROM UsageToken u
INNER JOIN UsageTokenTemplate t
ON u.UsageTokenTemplId = t.UsageTokenTemplId
INNER JOIN TokenType y
ON t.TokenTypeId = y.TokenTypeId
WHERE u.customerid = @.customerid
AND u.status<100 /* could be frozen */
AND (u.Expires is null or u.Expires > getdate()) /*did not expire*/
AND (u.Value is null or u.Value>0)
ORDER BY y.Priority, u.Created


Thanks a lot.

|||

Ok, let's start here. First step is to unroll this stored procedure into a view so that we can reuse it later. Heh, it would figure that you would have this buried somewhere, this is definately the hardest part of unravelling your cursor logic, so here goes. I am going to make the assumption that a single user can not have two (or more) tokens created with the same priority created at the same "Created". If this assumption is not correct, please let me know what combination of fields would be required to ALWAYS return no more than a single record.

Coding by hand here, so might be a syntax error somewhere (sorry).

CREATE VIEW vw_CustomerUsageToken

AS

SELECT t1.customerid,t1.TokenTypeId,t1.Value,t1.Expires
FROM (SELECT u.customerid,t.TokenTypeId,u.Value,u.Expires,y.priority,u.created FROM UsageToken u
INNER JOIN UsageTokenTemplate t
ON u.UsageTokenTemplId = t.UsageTokenTemplId
INNER JOIN TokenType y
ON t.TokenTypeId = y.TokenTypeId
WHERE u.status<100 /* could be frozen */
AND (u.Expires is null or u.Expires > getdate()) /*did not expire*/
AND (u.Value is null or u.Value>0)) t1

LEFT JOIN (SELECT u.customerid,t.TokenTypeId,u.Value,u.Expires,y.priority,u.created FROM UsageToken u
INNER JOIN UsageTokenTemplate t
ON u.UsageTokenTemplId = t.UsageTokenTemplId
INNER JOIN TokenType y
ON t.TokenTypeId = y.TokenTypeId
WHERE u.status<100 /* could be frozen */
AND (u.Expires is null or u.Expires > getdate()) /*did not expire*/
AND (u.Value is null or u.Value>0)) t2 on t1.customerid=t2.customerid AND (t2.priority<t1.priority OR (t2.priority=t1.priority AND t2.created<t1.created))

WHERE t2.customerid IS NULLsql

Wednesday, March 28, 2012

help on SQL syntax ?

Dear all,
I am not so familar with SQL syntax.
Is there a good link where keywords and syntax are clearly explain ?
I am running SQL server 2000 Sp4 on server 2003.
regards
sergeHi serge,
read the "BOL"
http://www.aspfaq.com/show.asp?id=2229
HTH, Jens Suessmeyer,|||Hi
Books online is a good source for a lot of information and should be the
first thing to look at. If it is not in your SQL Server program group then
you can download it from
http://www.microsoft.com/downloads/...&displaylang=en
John
"serge calderara" wrote:

> Dear all,
> I am not so familar with SQL syntax.
> Is there a good link where keywords and syntax are clearly explain ?
> I am running SQL server 2000 Sp4 on server 2003.
> regards
> serge|||If BOL is not your thing you might try this free book:
http://www.managedtime.com/freesqlbook.php3
Msql

help on SQL server backup!

Dear all,
I have a problem right now. We got a production server running. Now we want
to setup an another identical database at a remote office. The problem is
that replication can't be done between the two offices. To make sure the
remote office will have as much data as the production server. What shall I
do?
Help!!!!Hi
backup/restore commands. (see in BOL)
"big tony" <bigtony@.discussions.microsoft.com> wrote in message
news:C9CD538F-05AD-4CE4-8A87-45EAFEAEE024@.microsoft.com...
> Dear all,
> I have a problem right now. We got a production server running. Now we
want
> to setup an another identical database at a remote office. The problem is
> that replication can't be done between the two offices. To make sure the
> remote office will have as much data as the production server. What shall
I
> do?
> Help!!!!

help on SQL server backup!

Dear all,
I have a problem right now. We got a production server running. Now we want
to setup an another identical database at a remote office. The problem is
that replication can't be done between the two offices. To make sure the
remote office will have as much data as the production server. What shall I
do?
Help!!!!Hi
backup/restore commands. (see in BOL)
"big tony" <bigtony@.discussions.microsoft.com> wrote in message
news:C9CD538F-05AD-4CE4-8A87-45EAFEAEE024@.microsoft.com...
> Dear all,
> I have a problem right now. We got a production server running. Now we
want
> to setup an another identical database at a remote office. The problem is
> that replication can't be done between the two offices. To make sure the
> remote office will have as much data as the production server. What shall
I
> do?
> Help!!!!

help on SQL server backup!

Dear all,
I have a problem right now. We got a production server running. Now we want
to setup an another identical database at a remote office. The problem is
that replication can't be done between the two offices. To make sure the
remote office will have as much data as the production server. What shall I
do?
Help!!!!
Hi
backup/restore commands. (see in BOL)
"big tony" <bigtony@.discussions.microsoft.com> wrote in message
news:C9CD538F-05AD-4CE4-8A87-45EAFEAEE024@.microsoft.com...
> Dear all,
> I have a problem right now. We got a production server running. Now we
want
> to setup an another identical database at a remote office. The problem is
> that replication can't be done between the two offices. To make sure the
> remote office will have as much data as the production server. What shall
I
> do?
> Help!!!!
sql

Friday, March 23, 2012

Help on how to 1 way push data

Hi there
Maybe Im missing something but..
I have a order tracking system running on sales peoples laptop's. When they connect to the company Network (via dialup) at Night I want to push all off there orders to a named SQL, and then remove those orders from their own laptop.
So in a sense, Its like a one way merge with a delete, or even a push from MSDE to the main SQL server.
I dont want existing data pushed back to the laptop.. SO its all one way.
Any ideas? or help
Ryan,
I have seen merge used for this - you can have a filter of 1=2 on the
tables. This ensures that subscriber inserts are replicated to teh
publisher, and then deletes are replicated back because the filter is not
satisfied. However, this can be a bit buggy if inserts are still carried out
on the subscriber while the merge agent is running (some of the new rows
won't be removed when next running the merge agent). Provided you can
prevent this, or it won't happen in your particular business, then this is a
viable solution.
Alternatively, each laptop could be configured as a transactional publisher
with HO as a central subscriber and for the delete command, 'none' is
entered to prevent the replication of deletes.
Finally, you could use DTS/linked servers to accomplish the same thing.
Regards,
Paul Ibison
|||Hi Paul
Thanks for your reply. Could you just explain the
> you can have a filter of 1=2 on the
> tables. This ensures that subscriber inserts are replicated to teh
> publisher, and then deletes are replicated back because the filter is not
> satisfied.
please as this sounds about the right way - as the users will not be adding new records at the time of syncronisation (they are basically using the Win Xp Syncronisation tool i.e. Annonymous.
|||Ryan,
in the filter section of the publication properties, on the filter rows tab
you specify this filter:
SELECT <published_columns> FROM [dbo].[yourtable] WHERE 2=1
HTH,
Paul Ibison

Wednesday, March 21, 2012

Help on code in a SP

Hi,
I'm currently auditing some SQL servers to have an overview on what's
running/existing in the different databases.
On one of the server, I found User's Stored Procedures in MSDB databases
(which, I think is already not a good idea). My problem is that I can't get
the usage of the SPs.
All are built on the same model : all the code is written on 1 line only.
Here is the full code of one the SP:
-- beginning of the code --
create procedure <SP_Name> (@.IntID binary(8),@.Z_BranchID_Z int,@.Z_VS_Z
int,@.IconLibrary varchar(255)=null,@.IconID int=null,@.ShowCollections
bit=null,@.Z_VE_Z int=2147483647) as insert RTblClassExtension values
(@.IntID,@.Z_BranchID_Z,@.Z_VS_Z,@.Z_VE_Z,@.I
conLibrary,@.IconID,@.ShowCollections)
GO
-- end of the code --
If someone would have any clue abotu what's this SP is doing...
Thanks,
ChrisYou are trying to insert into the RTblClassExtension with the values passed.
What is that you would like to know here
HTH,
Vinod Kumar
MCSE, DBA, MCAD, MCSD
http://www.extremeexperts.com
Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp
"Chris V." <tophe_news@.hotmail.com> wrote in message
news:u0Lybtr1EHA.1152@.TK2MSFTNGP14.phx.gbl...
> Hi,
> I'm currently auditing some SQL servers to have an overview on what's
> running/existing in the different databases.
> On one of the server, I found User's Stored Procedures in MSDB databases
> (which, I think is already not a good idea). My problem is that I can't
get
> the usage of the SPs.
> All are built on the same model : all the code is written on 1 line only.
> Here is the full code of one the SP:
> -- beginning of the code --
> create procedure <SP_Name> (@.IntID binary(8),@.Z_BranchID_Z int,@.Z_VS_Z
> int,@.IconLibrary varchar(255)=null,@.IconID int=null,@.ShowCollections
> bit=null,@.Z_VE_Z int=2147483647) as insert RTblClassExtension values
>
(@.IntID,@.Z_BranchID_Z,@.Z_VS_Z,@.Z_VE_Z,@.I
conLibrary,@.IconID,@.ShowCollections)[vbc
ol=seagreen]
> GO
> -- end of the code --
> If someone would have any clue abotu what's this SP is doing...
> Thanks,
> Chris
>[/vbcol]|||I'm trying to understand what are theses procedures I have into MSDB.
On your opinion, what could be the usage of such insert ?
(I'm not, far from that, expert in SQL. so, any help will be appreciated)
Thx,
Chris
"Vinod Kumar" <vinodk_sct@.NO_SPAM_hotmail.com> wrote in message
news:cohev5$avs$1@.news01.intel.com...
> You are trying to insert into the RTblClassExtension with the values
passed.
> What is that you would like to know here
> --
> HTH,
> Vinod Kumar
> MCSE, DBA, MCAD, MCSD
> http://www.extremeexperts.com
> Books Online for SQL Server SP3 at
> http://www.microsoft.com/sql/techin.../2000/books.asp
> "Chris V." <tophe_news@.hotmail.com> wrote in message
> news:u0Lybtr1EHA.1152@.TK2MSFTNGP14.phx.gbl...
> get
only.
>
(@.IntID,@.Z_BranchID_Z,@.Z_VS_Z,@.Z_VE_Z,@.I
conLibrary,@.IconID,@.ShowCollections)[vbc
ol=seagreen]
>|||Like you I don't know what its used for either, however I
have in my database which sort of means that its actually
a Microsoft SP, and not a user one.
Sorry I can't be much of a help here, except to lay your
mind at rest.
Peter
"I may be drunk, Miss, but in the morning I will be sober
and you will still be ugly."
Winston Churchill

>--Original Message--
>I'm trying to understand what are theses procedures I
have into MSDB.
>On your opinion, what could be the usage of such insert ?
>(I'm not, far from that, expert in SQL. so, any help will
be appreciated)
>Thx,
>Chris
>"Vinod Kumar" <vinodk_sct@.NO_SPAM_hotmail.com> wrote in
message
>news:cohev5$avs$1@.news01.intel.com...
with the values[vbcol=seagreen]
>passed.
http://www.microsoft.com/sql/techin...tdoc/2000/books
.asp[vbcol=seagreen]
overview on what's[vbcol=seagreen]
Procedures in MSDB databases[vbcol=seagreen]
problem is that I can't[vbcol=seagreen]
written on 1 line[vbcol=seagreen]
>only.
-[vbcol=seagreen]
(8),@.Z_BranchID_Z int,@.Z_VS_Z[vbcol=seagreen]
int=null,@.ShowCollections[vbcol=seagreen
]
RTblClassExtension values[vbcol=seagreen]
>
(@.IntID,@.Z_BranchID_Z,@.Z_VS_Z,@.Z_VE_Z,@.I
conLibrary,@.IconID,
@.ShowCollections)
is doing...[vbcol=seagreen]
>
>.
>

Help on code in a SP

Hi,
I'm currently auditing some SQL servers to have an overview on what's
running/existing in the different databases.
On one of the server, I found User's Stored Procedures in MSDB databases
(which, I think is already not a good idea). My problem is that I can't get
the usage of the SPs.
All are built on the same model : all the code is written on 1 line only.
Here is the full code of one the SP:
-- beginning of the code --
create procedure <SP_Name> (@.IntID binary(8),@.Z_BranchID_Z int,@.Z_VS_Z
int,@.IconLibrary varchar(255)=null,@.IconID int=null,@.ShowCollections
bit=null,@.Z_VE_Z int=2147483647) as insert RTblClassExtension values
(@.IntID,@.Z_BranchID_Z,@.Z_VS_Z,@.Z_VE_Z,@.IconLibrary,@.IconID,@.ShowCollections)
GO
-- end of the code --
If someone would have any clue abotu what's this SP is doing...
Thanks,
ChrisYou are trying to insert into the RTblClassExtension with the values passed.
What is that you would like to know here
--
HTH,
Vinod Kumar
MCSE, DBA, MCAD, MCSD
http://www.extremeexperts.com
Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinfo/productdoc/2000/books.asp
"Chris V." <tophe_news@.hotmail.com> wrote in message
news:u0Lybtr1EHA.1152@.TK2MSFTNGP14.phx.gbl...
> Hi,
> I'm currently auditing some SQL servers to have an overview on what's
> running/existing in the different databases.
> On one of the server, I found User's Stored Procedures in MSDB databases
> (which, I think is already not a good idea). My problem is that I can't
get
> the usage of the SPs.
> All are built on the same model : all the code is written on 1 line only.
> Here is the full code of one the SP:
> -- beginning of the code --
> create procedure <SP_Name> (@.IntID binary(8),@.Z_BranchID_Z int,@.Z_VS_Z
> int,@.IconLibrary varchar(255)=null,@.IconID int=null,@.ShowCollections
> bit=null,@.Z_VE_Z int=2147483647) as insert RTblClassExtension values
>
(@.IntID,@.Z_BranchID_Z,@.Z_VS_Z,@.Z_VE_Z,@.IconLibrary,@.IconID,@.ShowCollections)
> GO
> -- end of the code --
> If someone would have any clue abotu what's this SP is doing...
> Thanks,
> Chris
>|||I'm trying to understand what are theses procedures I have into MSDB.
On your opinion, what could be the usage of such insert ?
(I'm not, far from that, expert in SQL. so, any help will be appreciated)
Thx,
Chris
"Vinod Kumar" <vinodk_sct@.NO_SPAM_hotmail.com> wrote in message
news:cohev5$avs$1@.news01.intel.com...
> You are trying to insert into the RTblClassExtension with the values
passed.
> What is that you would like to know here
> --
> HTH,
> Vinod Kumar
> MCSE, DBA, MCAD, MCSD
> http://www.extremeexperts.com
> Books Online for SQL Server SP3 at
> http://www.microsoft.com/sql/techinfo/productdoc/2000/books.asp
> "Chris V." <tophe_news@.hotmail.com> wrote in message
> news:u0Lybtr1EHA.1152@.TK2MSFTNGP14.phx.gbl...
> > Hi,
> >
> > I'm currently auditing some SQL servers to have an overview on what's
> > running/existing in the different databases.
> >
> > On one of the server, I found User's Stored Procedures in MSDB databases
> > (which, I think is already not a good idea). My problem is that I can't
> get
> > the usage of the SPs.
> > All are built on the same model : all the code is written on 1 line
only.
> >
> > Here is the full code of one the SP:
> >
> > -- beginning of the code --
> > create procedure <SP_Name> (@.IntID binary(8),@.Z_BranchID_Z int,@.Z_VS_Z
> > int,@.IconLibrary varchar(255)=null,@.IconID int=null,@.ShowCollections
> > bit=null,@.Z_VE_Z int=2147483647) as insert RTblClassExtension values
> >
>
(@.IntID,@.Z_BranchID_Z,@.Z_VS_Z,@.Z_VE_Z,@.IconLibrary,@.IconID,@.ShowCollections)
> > GO
> >
> > -- end of the code --
> >
> > If someone would have any clue abotu what's this SP is doing...
> >
> > Thanks,
> > Chris
> >
> >
>|||Like you I don't know what its used for either, however I
have in my database which sort of means that its actually
a Microsoft SP, and not a user one.
Sorry I can't be much of a help here, except to lay your
mind at rest.
Peter
"I may be drunk, Miss, but in the morning I will be sober
and you will still be ugly."
Winston Churchill
>--Original Message--
>I'm trying to understand what are theses procedures I
have into MSDB.
>On your opinion, what could be the usage of such insert ?
>(I'm not, far from that, expert in SQL. so, any help will
be appreciated)
>Thx,
>Chris
>"Vinod Kumar" <vinodk_sct@.NO_SPAM_hotmail.com> wrote in
message
>news:cohev5$avs$1@.news01.intel.com...
>> You are trying to insert into the RTblClassExtension
with the values
>passed.
>> What is that you would like to know here
>> --
>> HTH,
>> Vinod Kumar
>> MCSE, DBA, MCAD, MCSD
>> http://www.extremeexperts.com
>> Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinfo/productdoc/2000/books
.asp
>> "Chris V." <tophe_news@.hotmail.com> wrote in message
>> news:u0Lybtr1EHA.1152@.TK2MSFTNGP14.phx.gbl...
>> > Hi,
>> >
>> > I'm currently auditing some SQL servers to have an
overview on what's
>> > running/existing in the different databases.
>> >
>> > On one of the server, I found User's Stored
Procedures in MSDB databases
>> > (which, I think is already not a good idea). My
problem is that I can't
>> get
>> > the usage of the SPs.
>> > All are built on the same model : all the code is
written on 1 line
>only.
>> >
>> > Here is the full code of one the SP:
>> >
>> > -- beginning of the code --
-
>> > create procedure <SP_Name> (@.IntID binary
(8),@.Z_BranchID_Z int,@.Z_VS_Z
>> > int,@.IconLibrary varchar(255)=null,@.IconID
int=null,@.ShowCollections
>> > bit=null,@.Z_VE_Z int=2147483647) as insert
RTblClassExtension values
>> >
>
(@.IntID,@.Z_BranchID_Z,@.Z_VS_Z,@.Z_VE_Z,@.IconLibrary,@.IconID,
@.ShowCollections)
>> > GO
>> >
>> > -- end of the code --
>> >
>> > If someone would have any clue abotu what's this SP
is doing...
>> >
>> > Thanks,
>> > Chris
>> >
>> >
>>
>
>.
>sql

Monday, March 19, 2012

Help needed with this Error message while running a DTS package

Hi

I am trying to import a excel file into a table but when i run it i am getting this error and i am not sure what this eror is

- Copying to [ICCStatements].[dbo].[Sheet1$] (Error)

Messages

Error 0xc0202009: Data Flow Task: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80004005.
An OLE DB record is available. Source: "Microsoft SQL Native Client" Hresult: 0x80004005 Description: "Unspecified error".
(SQL Server Import and Export Wizard)

Error 0xc020901c: Data Flow Task: There was an error with input column "AdminShowInKit" (148) on input "Destination Input" (102). The column status returned was: "The value violated the integrity constraints for the column.".
(SQL Server Import and Export Wizard)

Error 0xc0209029: Data Flow Task: SSIS Error Code DTS_E_INDUCEDTRANSFORMFAILUREONERROR. The "input "Destination Input" (102)" failed because error code 0xC020907D occurred, and the error row disposition on "input "Destination Input" (102)" specifies failure on error. An error occurred on the specified object of the specified component. There may be error messages posted before this with more information about the failure.
(SQL Server Import and Export Wizard)

Error 0xc0047022: Data Flow Task: SSIS Error Code DTS_E_PROCESSINPUTFAILED. The ProcessInput method on component "Destination - Sheet1$" (89) failed with error code 0xC0209029. The identified component returned an error from the ProcessInput method. The error is specific to the component, but the error is fatal and will cause the Data Flow task to stop running. There may be error messages posted before this with more information about the failure.
(SQL Server Import and Export Wizard)

Error 0xc0047021: Data Flow Task: SSIS Error Code DTS_E_THREADFAILED. Thread "WorkThread0" has exited with error code 0xC0209029. There may be error messages posted before this with more information on why the thread has exited.
(SQL Server Import and Export Wizard)

Any help will be appreciated.. RegardsKArenThe key error is this:

Error 0xc020901c: Data Flow Task: There was an error with input column "AdminShowInKit" (148) on input "Destination Input" (102). The column status returned was: "The value violated the integrity constraints for the column.".
(SQL Server Import and Export Wizard)

There seems to be an error in the AdminShowInKit column. Possibly a missing value.

Monday, March 12, 2012

Help Needed on DTC

Hi,
I'm having problems while running distributed transactions on two different servers. I
have two servers 'EPOOL5' and 'EPOOL9' respectively running SQl servers.
I have linked both the servers using sp_addlinkedserver 'EPOOL5' and sp_addlinkedserver 'EPOOL9' on EPOOL9 and EPOOL5 respectively. I have created a user PCRCCTEST on both the server databases. The databases being VDPMASTER on EPOOL5 and VDPMASTERTEST on EPOOL9. I have given the user PCRCCTEST proper privileges to access the tables in the respective databases.
I have started DTC on both the servers EPOOL9 and EPOOL5.

Now when I execute a query say select * from epool9.vdpmastertest.dbo.project_master from EPOOL5, the query is successfully executed and the rows are retrieved. When I insert rows similary, the rows are getting inserted. I am facing a problem when I try to run transactions. i.e I have created a stored procedure 'test' on VDPMASTER database on EPOOL5. 'Project_Master' being the table in EPOOL9 VDPMASTERTEST database. The user PCRCCTEST has privileges to insert data into Project_Master.

create procedure test
as
begin distributed transaction

insert into epool9.VDPMASTERTEST.dbo.Project_Master
(project_id,quality_id,project_name,project_client ,start_date,end_date,
project_active,project_master_update_flag,project_ master_updated_by, project_master_updated_on)
values (447,'3433','manufacturing','firstbank','02/22/2002','02/23/2003','Y','I',1,getdate())

if @.@.error=0
begin
commit transaction
print 'commitTest'
end
else
begin
print 'rollbackTest'
rollback transaction
end

When I execute this stored procedure from EPOOL5 server, I get the following error.

Server: Msg 7392, Level 16, State 2, Procedure test, Line 5
Could not start a transaction for OLE DB provider 'SQLOLEDB'.
[OLE/DB provider returned message: Only one transaction can be active on this session.]

I would be grateful if you could help me on this.
Thanks in advance
P.C. VaidyanathanI believe that this error is caused by nested transactions

begin tran
begin tran

commit tran
commit tran

To prevent your stored procedure from creating nested transactions you can check @.@.TRANCOUNT to see if a BEGIN TRAN has already been issued.

CREATE PROCEDURE test
as
DECLARE @.tfTran tinyint

--
-- Start Transaction
--
IF (@.@.TRANCOUNT = 0) BEGIN
SET @.tfTran = 1
BEGIN DISTRIBUTED TRANSACTION
END
ELSE
SET @.tfTran = 0

INSERT INTO epool9.VDPMASTERTEST.dbo.Project_Master
(project_id,quality_id,project_name,
project_client,start_date,end_date,
project_active,project_master_update_flag,
project_master_updated_by, project_master_updated_on)
values
(447,'3433','manufacturing','firstbank',
'02/22/2002','02/23/2003','Y','I',1,getdate())

IF @.@.error=0 BEGIN
IF (@.tfTran = 1) BEGIN
COMMIT TRAN
PRINT 'Commit Test'
END
END
ELSE BEGIN
IF (@.tfTran = 1) BEGIN
ROLLBACK TRAN
PRINT 'Rollback Test'
END
END

Friday, March 9, 2012

Help Needed Configuring ODBC

In the Office we have a Win2000 Server running MS SQL Server 2000. I know
the servers external IP address (xxx.xxx.xxx.xxx) and we have a sub-domain
set up (subname.mycompserver.com). I have a login and password into the
server as well as the SQL login and password. The firewall is open on port
1433. From my office PC, I can access SQL, using ODBC, with Access or my
Perl programs.
At home, I'm running WinXP Pro. Although it shouldn't have been necessary,
I installed MS SQL Server client. I connect to the Internet using a Comcast
cable modem and do not have a static IP address. Whenever I try to set up
ODBC to access my office's SQL server using ODBC Data Source Administrator
/ Add SQL Server, it fails with the following error message:
Connection Failed
SQL State: '01000'
SQL Server Error: 10060
[Microsoft][ODBC Server Driver][TCP/IP Sockets]Connection Open (Connect())
Connection Failed:
SQL State: '08001'
SQL Server Error: 17
[Microsoft][ODBC Server Driver][TCP/IP Sockets]SQL Server does not exist or
access denied.
Is it possible to establish this ODBC connection into SQL and, if so, what
am I doing wrong. Thanks.
Fred
Hello Fred,
The only thing I can think is that firewall at your work is blocking 1433. The Connect() message means that a TCP/IP
socket was not created. From your office's server machine go to http://aboutmyip.com and see if port is open.
Fred Goldberg wrote:

> In the Office we have a Win2000 Server running MS SQL Server 2000. I know
> the servers external IP address (xxx.xxx.xxx.xxx) and we have a sub-domain
> set up (subname.mycompserver.com). I have a login and password into the
> server as well as the SQL login and password. The firewall is open on port
> 1433. From my office PC, I can access SQL, using ODBC, with Access or my
> Perl programs.
> At home, I'm running WinXP Pro. Although it shouldn't have been necessary,
> I installed MS SQL Server client. I connect to the Internet using a Comcast
> cable modem and do not have a static IP address. Whenever I try to set up
> ODBC to access my office's SQL server using ODBC Data Source Administrator
> / Add SQL Server, it fails with the following error message:
> Connection Failed
> SQL State: '01000'
> SQL Server Error: 10060
> [Microsoft][ODBC Server Driver][TCP/IP Sockets]Connection Open (Connect())
> Connection Failed:
> SQL State: '08001'
> SQL Server Error: 17
> [Microsoft][ODBC Server Driver][TCP/IP Sockets]SQL Server does not exist or
> access denied.
> Is it possible to establish this ODBC connection into SQL and, if so, what
> am I doing wrong. Thanks.
> Fred
|||I truly appreciated your prompt reply to my question. Your answer
implies that this is doable.
I connected to our server using Remote Desktop, brought up IE and ran
http://aboutmyip.com. And, as you expected, Port 1433 is closed. My MIS
guys swore they opened it for me.
I'll have to get the port opened and try again. Thanks so much.
Fred
*** Sent via Developersdex http://www.codecomments.com ***
Don't just participate in USENET...get rewarded for it!

Friday, February 24, 2012

HELP ME TO OPTIMIZE QUERY

Hello friends,

I'm facing performance related problem while running following query on SQL Server 2000.

This query is basically used to find last location of each unit that are passed. Here I am passing data like "'26','27','28','29','30','31','32','33','34','35','36','37','38','39','40','41','42','43','44','45','46','47','48','49','50'" in @.Units variable. But it takes too much time and I don't get output. Table is having around5 Million records.

Query:

SELECT Alias, tblUnit.UnitID, Location, Latitude, Longitude,Convert(varchar(10),UnitHistoryDate,1) + ' ' + substring(Convert(varchar(40),UnitHistoryDate,109),12,9) + ' ' + substring(Convert(varchar(40),UnitHistoryDate,109),25,2) as [Date/Time], unithistoryid

FROM tblUnit INNER JOIN

tblUnitHistory ON tblUnit.UnitID = tblUnitHistory.UnitID

WHERE tblUnitHistory.UnitHistoryDate

IN (SELECT MAX(UnitHistoryDate) FROM tblUnitHistory WHERE tblUnitHistory.UnitID in (' + @.Units + ') GROUP BY tblUnitHistory.UnitID)

AND tblUnit.UnitID in (' + @.Units + ')

ORDER BY tblUnit.UnitID

Table Structure:

UnitHistoryID int Primary Key

UnitID int

Location varchar(200)

Latitude decimal 9

Longitude decimal 9

Speed decimal5

BatteryVoltage decimal5

ReasonCode int

DistanceFromLastLocation decimal9

UnitHistoryDate datetime

Indexes:

1. Clustered Index on ColumnUnitID

2. Non-clustered Index on ColumnUnitHistoryDate

3. Non-clustered Index on ColumnUnitHistoryID

Please help me to write optimize query and suggest me the steps to require making this query faster. Any help is appreciated. Thanks in advance.

Regards,

Sandeep

try to limit processed records by:

'SELECT Alias, tblUnit.UnitID, Location, Latitude, Longitude,Convert(varchar(10),UnitHistoryDate,1) + ' ' + substring(Convert(varchar(40),UnitHistoryDate,109),12,9) + ' ' + substring(Convert(varchar(40),UnitHistoryDate,109),25,2) as [Date/Time], unithistoryid

FROM (SELECT * FROM tblUnit

where

AND tblUnit.UnitID in (' + @.Units + '))tblUnit

INNER JOIN

(SELECT tblUnitHistory.UnitID , MAX(UnitHistoryDate) UnitHistoryDate FROM (SELECT * FROM tblUnitHistory WHERE tblUnitHistory.UnitID in (' + @.Units + ')) tblUnitHistory GROUP BY tblUnitHistory.UnitID) tblUnitHistory

ON tblUnit.UnitID = tblUnitHistory.UnitID

ORDER BY tblUnit.UnitID'

I hope that it will work, The Idea is to limit number of records used in join to minimum.