Showing posts with label seconds. Show all posts
Showing posts with label seconds. Show all posts

Monday, March 19, 2012

HH:MM:SS Format

In MS reporting, how would I convert seconds into HH:MMTongue TiedS format?

Hello,

Try this as the expression for your textbox:

=Floor(Fields!TotalSeconds.Value / 3600) & ":"

& Floor(Fields!TotalSeconds.Value / 60) - Floor(Fields!TotalSeconds.Value / 3600) * 60 & ":"

& Fields!TotalSeconds.Value - Floor(Fields!TotalSeconds.Value / 60) * 60

Hope this helps.

Jarret

|||

Since you get to use VB in reports, try the following:

Code Snippet

Format$(Timeserial(0, 0, seconds), "hh:mm:ss")

Larry

|||Thanks Larry, this worked!|||This method worked also. Thanks Jarret.

Wednesday, March 7, 2012

Help: Why excute a stored procedure need to more 30 seconds, but direct excute the query o

Hello to all,

I have a stored procedure. If i give this commandexce ShortestPath 3418, '4125', 5 in a script and excute it. It takes more 30 seconds time to be excuted.

but i excute it with the same parameters direct in Microsoft SQL Server Management Studio , It takes only under 1 second time

I don't know why?

Maybe can somebody help me?

thanks in million

best Regards

Pinsha

My Procedure Codes are here:

set ANSI_NULLSON

set QUOTED_IDENTIFIERON

GO

-- =============================================

-- Author: <Author,,Name>

-- Create date: <Create Date,,>

-- Description: <Description,,>

-- =============================================

ALTERPROCEDURE [dbo].[ShortestPath](@.IDMemberint, @.IDOther varchar(1000),@.Levelint, @.Path varchar(100)=null output)

AS

BEGIN

if( @.Level= 1)

begin

select @.Path=convert(varchar(100),IDMember)

from wtcomValidRelationships

where wtcomValidRelationships.[IDMember]= @.IDMember

andPATINDEX('%'+@.IDOther+'%',(select RelationshipIDsfrom wtcomValidRelationshipswhere IDMember= @.IDMember))> 0

end

if(@.Level= 2)

begin

selecttop 1 @.Path=convert(varchar(100),A.IDMember)+'-'+convert(varchar(100),B.IDMember)

from wtcomValidRelationshipsas A, wtcomValidRelationshipsas B

where A.IDMember= @.IDMemberandcharindex(convert(varchar(100),B.IDMember),A.RelationshipIDS)> 0

andPATINDEX('%'+@.IDOther+'%',B.RelationshipIDs)> 0

end

if(@.Level= 3)

begin

selecttop 1 @.Path=convert(varchar(100),A.IDMember)+'-'+convert(varchar(100),B.IDMember)+'-'+convert(varchar(100),C.IDMember)

from wtcomValidRelationshipsas A, wtcomValidRelationshipsas B, wtcomValidRelationshipsas C

where A.IDMember= @.IDMemberandcharindex(convert(varchar(100),B.IDMember),A.RelationshipIDS)> 0

andcharindex(convert(varchar(100),C.IDMember),B.RelationshipIDs)> 0andPATINDEX('%'+@.IDOther+'%',C.RelationshipIDs)> 0

end

if( @.Level= 4)

begin

selecttop 1 @.Path=convert(varchar(100),A.IDMember)+'-'+convert(varchar(100),B.IDMember)+'-'+convert(varchar(100),C.IDMember)+'-'+convert(varchar(100),D.IDMember)

from wtcomValidRelationshipsas A, wtcomValidRelationshipsas B, wtcomValidRelationshipsas C, wtcomValidRelationshipsas D

where A.IDMember= @.IDMemberandcharindex(convert(varchar(100),B.IDMember),A.RelationshipIDS)> 0

andcharindex(convert(varchar(100),C.IDMember),B.RelationshipIDs)> 0andcharindex(convert(varchar(100),D.IDMember), C.RelationshipIDs)> 0

andPATINDEX('%'+@.IDOther+'%',D.RelationshipIDs)> 0

end

if(@.Level= 5)

begin

selecttop 1 @.Path=convert(varchar(100),A.IDMember)+'-'+convert(varchar(100),B.IDMember)+'-'+convert(varchar(100),C.IDMember)+'-'+convert(varchar(100),D.IDMember)+'-'+convert(varchar(100),E.IDMember)

from wtcomValidRelationshipsas A, wtcomValidRelationshipsas B, wtcomValidRelationshipsas C, wtcomValidRelationshipsas D, wtcomValidRelationshipsas E

where A.IDMember= @.IDMemberandcharindex(convert(varchar(100),B.IDMember),A.RelationshipIDS)> 0

andcharindex(convert(varchar(100),C.IDMember),B.RelationshipIDs)> 0andcharindex(convert(varchar(100),D.IDMember), C.RelationshipIDs)> 0

andcharindex(convert(varchar(100),E.IDMember),D.RelationshipIDs)> 0andPATINDEX('%'+@.IDOther+'%',E.RelationshipIDs)> 0

end

if(@.Level= 6)

begin

selecttop 1 @.Path=''from wtcomValidRelationships

end

END

Was bothexce ShortestPath 3418, '4125', 5 and the run of the SQL within the sp done within MS SQL Management Studio with the same account on both sessions?

If yes then the problem may be due to the way the sp was initially run - it is likely to need recompiling look upsp_recompile in books on line.

You run it like this:

EXEC sp_recompile N'TABLENAME'; -- where TABLENAME is name of one of the tables the s.p. acts on.

Where

a|||

Was bothexce ShortestPath 3418, '4125', 5 and the run of the SQL within the sp done within MS SQL Management Studio with the same account on both sessions?

If yes then the problem may be due to the way the sp was initially run - it is likely to need recompiling look upsp_recompile in books on line.

You run it like this:

EXEC sp_recompile N'TABLENAME'; -- where TABLENAME is name of one of the tables the s.p. acts on.

Where

|||

Was bothexce ShortestPath 3418, '4125', 5 and the run of the SQL within the sp done within MS SQL Management Studio with the same account on both sessions?

If yes then the problem may be due to the way the sp was initially run - it is likely to need recompiling look upsp_recompile in books on line.

You run it like this:

EXEC sp_recompile N'TABLENAME'; -- where TABLENAME is name of one of the tables the s.p. acts on.

Where

a stored|||

Was bothexce ShortestPath 3418, '4125', 5 and the run of the SQL within the sp done within MS SQL Management Studio with the same account on both sessions?

If yes then the problem may be due to the way the sp was initially run - it is likely to need recompiling look upsp_recompile in books on line.

You run it like this:

EXEC sp_recompile N'TABLENAME'; -- where TABLENAME is name of one of the tables the s.p. acts on.

This problem can happen , whereever a stored procedure has radically paths through it with reference to the most efficient way of processing.

|||

Hello,

I have tried this EXEC sp_recompile N'TABLENAME. But this problem can not be resolved.

Somebody tell me that thecharindex function is not good for searching. Better use in function. I tried to use in function. Another Problem comes: Member 3430 has Relationship with Member 3418, but i usedin function, Member 3430 can not be found that it has relationship with Member 3418. Here is my test code:

declare @.IDMint;

declare @.IDO varchar(100);

set @.IDM= 3418;

set @.IDO='3430'

selectconvert(varchar(100),IDMember)

from wtcomValidRelationships

where wtcomValidRelationships.[IDMember]= 3418

and(@.IDOin(select B.RelationshipIDsfrom wtcomValidRelationshipsas Bwhere B.IDMember= @.IDM))

Maybe somebody can help me? Thanks

Best Regards

Pinsha

|||

Try splittingdbo].[ShortestPath] intodbo].[ShortestPathLevel1],dbo].[ShortestPathLevel2] ect.so that each only has the logic to process one level. This will ensure that each is optimised correctly.

Sunday, February 19, 2012

HELP: Delayed Inserts in SQL Server!

Hi all,
I have a small table with the following columns:
Refno (int), CampaignID(int), Value (int)
Sometimes a record takes >30 - 40 seconds to write. Is there a way to
ensure that a record is written in a timely manner?
Other info: I do have a stored procedure which loops the table waiting
for a response:
WHILE ((SELECT COUNT(*) FROM DIALANSWERLOOKUP WHERE REFNO = @.REFNO) = 0)
AND @.LOOPCOUNTER < 30
BEGIN
SET @.LOOPCOUNTER = @.LOOPCOUNTER + 1
/* Pause Loop Delay in hh:mm:ss:ms format */
WAITFOR DELAY '00:00:00.200'
END
Also, once a record is read, it is deleted from the table. Could the
deletes be locking the table?
Thank you for ANY help.
--
Lucas Tam (REMOVEnntp@.rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/Your deletes and your looping SELECT can both be blocking the inserts.
Can you post DDL for the table, including any indexes and constraints?
Also, how many rows are in the table?
Your loop might be more efficient expressed as:
WHILE NOT EXISTS (SELECT * FROM DIALANSWERLOOKUP WHERE REFNO = @.REFNO)
Adam Machanic
SQL Server MVP
http://www.sqljunkies.com/weblog/amachanic
--
"Lucas Tam" <REMOVEnntp@.rogers.com> wrote in message
news:Xns959B8FF7AC71Dnntprogerscom@.140.99.99.130...
> Hi all,
> I have a small table with the following columns:
> Refno (int), CampaignID(int), Value (int)
> Sometimes a record takes >30 - 40 seconds to write. Is there a way to
> ensure that a record is written in a timely manner?
>
> Other info: I do have a stored procedure which loops the table waiting
> for a response:
> WHILE ((SELECT COUNT(*) FROM DIALANSWERLOOKUP WHERE REFNO = @.REFNO) = 0)
> AND @.LOOPCOUNTER < 30
> BEGIN
> SET @.LOOPCOUNTER = @.LOOPCOUNTER + 1
> /* Pause Loop Delay in hh:mm:ss:ms format */
> WAITFOR DELAY '00:00:00.200'
> END
> Also, once a record is read, it is deleted from the table. Could the
> deletes be locking the table?
> Thank you for ANY help.
> --
> Lucas Tam (REMOVEnntp@.rogers.com)
> Please delete "REMOVE" from the e-mail address when replying.
> http://members.ebay.com/aboutme/coolspot18/|||"Lucas Tam" <REMOVEnntp@.rogers.com> wrote in message
news:Xns959B8FF7AC71Dnntprogerscom@.140.99.99.130...
> Hi all,
> I have a small table with the following columns:
> Refno (int), CampaignID(int), Value (int)
> Sometimes a record takes >30 - 40 seconds to write. Is there a way to
> ensure that a record is written in a timely manner?
>
> Other info: I do have a stored procedure which loops the table waiting
> for a response:
> WHILE ((SELECT COUNT(*) FROM DIALANSWERLOOKUP WHERE REFNO = @.REFNO) = 0)
> AND @.LOOPCOUNTER < 30
> BEGIN
> SET @.LOOPCOUNTER = @.LOOPCOUNTER + 1
> /* Pause Loop Delay in hh:mm:ss:ms format */
> WAITFOR DELAY '00:00:00.200'
> END
> Also, once a record is read, it is deleted from the table. Could the
> deletes be locking the table?
> Thank you for ANY help.
>
What version of SQL Server are you running? I am assuming 2000.
What indexes are on the table?
Why do you have a WHILE loop running? That is most likely the cause of your
problem. It is probably holding locks on the table while an INSERT is
attempting to grab locks.
Is the looping doing something for you? Some type of notification? Could
you use a trigger on INSERT to accomplish the same task without using the
loop?
Rick Sawtell
MCT, MCSD, MCDBA|||"Adam Machanic" <amachanic@.hotmail._removetoemail_.com> wrote in
news:eSEjFmcxEHA.2012@.TK2MSFTNGP15.phx.gbl:
> Can you post DDL for the table, including any indexes and constraints?
> Also, how many rows are in the table?
Approximately 20 - 30 rows at a time. After a record is read, it is deleted
from the table.
There are no indexes and constraints on the table. I am running SQL Server
2000.
CREATE TABLE [dbo].[DialAnswerLookup] (
[campID] [int] NOT NULL ,
[refno] [int] NOT NULL ,
[answeredby] [int] NULL
) ON [PRIMARY]
GO
The While loop is used for notification - An ASP script executes a stored
procedure which loops the table waiting for the insert. Once the insert is
completed, the loop will complete and the value is returned to the ASP
page.
--
Lucas Tam (REMOVEnntp@.rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/|||"Rick Sawtell" <quickening@.msn.com> wrote in
news:uoA11mcxEHA.2624@.TK2MSFTNGP11.phx.gbl:
> What version of SQL Server are you running? I am assuming 2000.
Yes, SQL Server 2000.
> What indexes are on the table?
There are no indexes - I dropped all indexes in hopes that the INSERT
query will run faster.
> Why do you have a WHILE loop running? That is most likely the cause
> of your problem. It is probably holding locks on the table while an
> INSERT is attempting to grab locks.
The While loop is used for notification - An ASP script executes a
stored procedure which loops the table waiting for the insert to
complete. Once the insert is completed, the loop will find the record
and the value is returned to the ASP page. If no value is found within X
seconds the SP exits and the default value returned.
> Is the looping doing something for you? Some type of notification?
> Could you use a trigger on INSERT to accomplish the same task without
> using the loop?
Do you know of any other way to pause the execution of a select
statement and wait for a notification? A trigger *would* be nice... but
the problem is that the value must be returned to an external process (a
VoiceXML server which can only call webpages):
Here is the DDL for the table in case it might help you.
CREATE TABLE [dbo].[DialAnswerLookup] (
[campID] [int] NOT NULL ,
[refno] [int] NOT NULL ,
[answeredby] [int] NULL
) ON [PRIMARY]
GO
Lucas Tam (REMOVEnntp@.rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/|||You could start by defining a primary key... Refno, perhaps?
And maybe ease up the SELECT loop a bit, and/or use a (NOLOCK) hint to
ensure that it doesn't hold locks on the table...
--
Adam Machanic
SQL Server MVP
http://www.sqljunkies.com/weblog/amachanic
--
"Lucas Tam" <REMOVEnntp@.rogers.com> wrote in message
news:Xns959B95DA8324nntprogerscom@.140.99.99.130...
> "Adam Machanic" <amachanic@.hotmail._removetoemail_.com> wrote in
> news:eSEjFmcxEHA.2012@.TK2MSFTNGP15.phx.gbl:
> > Can you post DDL for the table, including any indexes and constraints?
> > Also, how many rows are in the table?
> Approximately 20 - 30 rows at a time. After a record is read, it is
deleted
> from the table.
> There are no indexes and constraints on the table. I am running SQL Server
> 2000.
> CREATE TABLE [dbo].[DialAnswerLookup] (
> [campID] [int] NOT NULL ,
> [refno] [int] NOT NULL ,
> [answeredby] [int] NULL
> ) ON [PRIMARY]
> GO
>
> The While loop is used for notification - An ASP script executes a stored
> procedure which loops the table waiting for the insert. Once the insert is
> completed, the loop will complete and the value is returned to the ASP
> page.
> --
> Lucas Tam (REMOVEnntp@.rogers.com)
> Please delete "REMOVE" from the e-mail address when replying.
> http://members.ebay.com/aboutme/coolspot18/