Hi,
I have a SQL Query with some if else blocks and some insert statements in it. When the T-SQL bactch is executed as Execute SQL Task in SSIS, it takes around 55 minutes.
When the same query is executed in SSMS, it takes around 12 minutes.
The T-SQL which I am using is similar to the statement given below:
===============================================================================
DECLARE @var1 DATETIME
,@var2 DATETIME
,@var3 bit
,@var4 bit
IF NOT EXISTS( select * from tab where cond)
BEGIN
SELECT @var1 = ISNULL(MIN(col1)-1, 0), @var2 = ISNULL(MAX(col1), 0), @var3 = 1
FROM tab2(NOLOCK)
INSERT staement
INSERT staement
SELECT FROM tab2(NOLOCK)
WHERE col1 > @var2 AND col1 <= @var1
END
ELSE
----**** Incremental Pull ****----
BEGIN
IF NOT EXISTS(SELECT * FROM tab)
BEGIN
SELECT @var1 = MAX(col1), @var3 = 0
FROM tab2 (NOLOCK)
UPDATE tab2
SET col1 = @var1
SELECT @var2 = col2
FROM tab2 (NOLOCK)
INSERT staement
SELECT FROM tab2(NOLOCK)
WHERE col1 > @var2 AND col1 <= @var1
END
ELSE
BEGIN
SELECT @var1 = col1 , @var2 = col2
FROM tab (NOLOCK)
END
END
SELECT @var4 = CASE WHEN (ISNULL(DATEDIFF(DAY,@var2,@var1),0 )<= 7) THEN 1
ELSE 0 END
SELECT CONVERT(VARCHAR(100),ISNULL(MAX(@var2),0),121) AS a
, CONVERT(VARCHAR(100),ISNULL(MAX(@var1),0),121) AS b
, @var3 AS c
, CASE WHEN (@var4 = 1) THEN CAST(0 AS BIT)
ELSE @var4 END AS d
,CONVERT(VARCHAR(100),GETDATE(),121) AS e
============================================================================
Please let me know the reason why its taking so much time in SSIS when compared to the query executed in SSMS.
Thanks in advance.
Raksha