SP Behaving Strangely

Sep 20, 2005

Hi All,
I have a DB of 100Gigs.
I have a SP which I came to knw frm developer that it is taking some more than 20 mins. Though when I just run the code frm the SP and replace the variables in the query with the values which I use in the executing the SP it completes in 2 mins.

I have recomiled the SP, drop and recreated the same.
I have updated the statistics of entire database checked whether the biggest table is having any defragmentation.

Any clues on this weird behaviour.
I have SQL Server 2000 with SP3.

View 3 Replies


ADVERTISEMENT

SQL Server DATEDIFF Behaving Badly

May 10, 2004

Hi,

I'm using the following SQL String in an ASP script with SQl Server:

SELECT time, DATEDIFF(minute, time, '18:00:00') AS difference FROM appointments

I have two appointments in the database - one with a time of 11:00 and one with a time of 14:00.

When I run this SQL query, 'difference' comes out exactly 48 hours more than it should do. So for the first appointment, it says that the difference is 3300 minutes and for the second it is 3120 minutes.

Any idea why this is happening? Is it something to do with the fact that I'm not using dates in the datetime format?

Paul

View 14 Replies View Related

Order By Caluse Behaving Differently

May 22, 2008

Hi Guys,

There is an int filed in my table called "WeekNo" and when I use order by WeekNo Desc, I am getting the following result.
9
8
7
7
6
5
4
3
2
18
17
16
15
15
14
13
13
12
11
10
10
1

This does not seem right, can anyone comment why i am getting this result.

Many Thanks

View 4 Replies View Related

ForEachLoop Task Not Behaving As Expected

Mar 30, 2007

Hi,



I have a ForEach Loop that has 3 script tasks in it.



I have them set up so that they execute in order, such as:



script1 ---> script2 ---> script3



script1 creates a file

script2 creates a file

script3 compares the files using a diff command



Problem is, when I execute the container, it shows that script3 finishes BEFORE script2, which of course gives an error b/c the file from script2 doesn't exist yet.



The error is "The system cannot find the file specified".



Thanks



View 2 Replies View Related

MAX Of TOP In Derived Table Behaving Strange

Feb 19, 2008



Hi,

I am working for my client on SQL 2005 Enterprise & observed a strange behaviour. Consider a table(EMPTABLE) as below:









PK, INT

VARCHAR


EMPID

EMPNAME


1

A


2

B


3

C


4

D


5

E


6

F


7

G


8

H


9

I


10

J


Now, I wanted the 5th highest EMPID from 2 from the table. Now, we know that the SQL

SELECT TOP 6 EMPID FROM EMPTABLE WHERE EMPID >=2 should (from all other possibilities) return me the desired value as the last row of the output table. I tried to get this in a derived table & get the MAX value i.e.

SELECT MAX(EMPID) FROM
(
SELECT TOP 6 EMPID FROM EMPTABLE WHERE EMPID >=2
) der

But this returns me 10, when I would've thought 7 was the expected answer

I remodified my query as mentioned below to strangely get 7 as the result...
SELECT MAX(EMPID) FROM
(
SELECT TOP 6 EMPID FROM EMPTABLE WHERE EMPID >=2 ORDER BY EMPID ASC
) der


How did the ORDER BY hep it???

Also, if I use
SELECT MAX(EMPID) FROM
(
SELECT TOP 6 EMPID FROM EMPTABLE WHERE EMPID >2
) der


I get the same result without having to specify the ORDER BY in my derived TABLE...

I tried looking for similar threads. But nothing could explain this to me...

If anyone knows what I am not able to understand, please let me know.

View 6 Replies View Related

Script Task To Compare File From FTP With File On Local Archive Behaved Strangely!

May 9, 2008

In my script task I have the following code. The task I'm trying to accomplish is:
If the filename on FTP can be found in the local archive folder of e: drive then show message "FileAlreadyThere" (I will ultimatley change it to do nothing); if the filename on FTP cannot be found in the local archive folder of e: drive then transfer the file to the local package folder on d: drive.

While the script task is executing I was watching it closely, but the problem i saw is that:
If some files on FTP are already in local archive folder and some are not, then it the files which are already in the archive folder are dumped to the package folder; then after that the files which are not in the archive folder are then dumped to the package folder. But I only want the new files on FTP to be transferred to the package folder for further processing.

Then after this is finished, I saw all the files in the package folder are refreshed one after another, after the first round of refresh the second round starts, after the second round finishes it then stopped. I saw it refreshes itself because the 'Date Modified' of the file changes. And I saw the script task turned green.

I don't see how the code below produced this result. Something is wrong in the logic of the loop? Anyone has any idea why it's behaving the way it is now? And how to change the code to accomplish what I want? Thanks a lot!!

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Imports System
Imports System.IO
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Runtime
Public Class ScriptMain
Public Sub Main()
Dim cm As ConnectionManager = Dts.Connections.Add("FTP")
cm.Properties("ServerName").SetValue(cm, "ftp2.name.com")
cm.Properties("ServerUserName").SetValue(cm, "username")
cm.Properties("ServerPassword").SetValue(cm, "password")
cm.Properties("ServerPort").SetValue(cm, "21")
cm.Properties("Timeout").SetValue(cm, "0")
cm.Properties("ChunkSize").SetValue(cm, "1000") '1000 kb
cm.Properties("Retries").SetValue(cm, "1")
Dim ftp As FtpClientConnection = New FtpClientConnection(cm.AcquireConnection(Nothing))
ftp.Connect()
ftp.SetWorkingDirectory("/directory")
Dim fileNames() As String
Dim folderNames() As String
ftp.GetListing(folderNames, fileNames)
If fileNames Is Nothing Then
MsgBox("NoFileOnFTP")
Else
Dim fileName As String
For Each fileName In fileNames
If File.Exists("c: emp" + fileName) Then
MsgBox("FileAlreadyThere")
Else
ftp.ReceiveFiles(fileNames, "c: emp", True, True)
End If
Next
End If

ftp.Close()
End Sub
End Class

View 3 Replies View Related

Trigger Behaving Differently On Multi-row Update

Aug 1, 2007

Let me set the scene:

I have an update trigger on a table. When a specific column is updated, I get the rowid from 'inserted' and then pass it via service broker to another database that will fire off a maintenance routine at a later time. This whole process seems to work fine if I update a single row at a time through Query Analyzer.

During testing (of the service broker part) I found that if in Query Analyzer I run an update that updates all of the records at once, then the trigger seems to fire only once for the entire process, therefore killing the rest of my process.

I would have thought that regardless of how a record was being updated the trigger would fire atomically for each row.

Any guidance on this would be MOST appreciated!

View 20 Replies View Related

SQL 2012 :: Identity Key (unique Column) Not Behaving Properly

Jul 19, 2013

I've seen this error on several of my databases again and again this week:

Violation of PRIMARY KEY constraint 'PK_XXXX'. Cannot insert duplicate key in object 'dbo.MyTable'. The duplicate key value is (whatever number here). The statement has been terminated.

The thing is, the PK is unique, and the INSERT statement does not touch that column, it touches the other ones. So SQL2012 is the one that automatically generates the next and unique available value.

How can be possible that the value to be inserted (generated by SQL2012) is a duplicate one? By the way, this was not happening on the previous SQL2005 or SQL2008 server where the databases were being hosted.

Here's my SQL 2012 version: 11.0.3000.0 (SP1 applied). Runs on top of a Win2008R2 Cluster.

View 9 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved