Solved

Execute SQL Task Result Set Error

Posted on 2009-04-06
17
2,530 Views
Last Modified: 2013-11-10
Hi
I am trying to excute this SQL in the Excute SQL Task and store the value in a variable ... When i do the same i get the output as  EXISTS in the Management Studio.. But in here when i try to do the same by setting the ResultSet to Single Row, ResultName (Index) =0 and variable name to a variable of datatype Varchar ...I get the error as below..Am i doing something wrong?

Progress: Executing query "Declare @I Varchar
Set @I = ((SELECT Table_NAme FR...". - 50 percent complete
Error: No result rowset is associated with the execution of this query.
[Execute SQL Task] Error: An error occurred while assigning a value to variable "Variable": "Exception from HRESULT: 0xC0015005".
Declare @I Varchar
Set @I = ((SELECT Table_NAme FROM INFORMATION_SCHEMA.TABLES
where TABLE_NAME = 'Data_0409'))
 Select Case 
 When @I <> NULL Or @I <> '0' Then 'Exists'
 Else 'Not Exists'
 End 
GO

Open in new window

0
Comment
Question by:danny1620
17 Comments
 
LVL 22

Accepted Solution

by:
PedroCGD earned 200 total points
ID: 24079667
You dont have a name associated with the column... maybe it's the problem...
Declare @I Varchar
Set @I = ((SELECT Table_NAme FROM INFORMATION_SCHEMA.TABLES
where TABLE_NAME = 'Data_0409'))
 Select (Case
 When @I <> NULL Or @I <> '0' Then 'Exists'
 Else 'Not Exists'
 End ) AS TEST
GO

Also check this link:
http://www.sqlis.com/post/The-Execute-SQL-Task.aspx

Regards,
Pedro

0
 
LVL 12

Expert Comment

by:udayakumarlm
ID: 24079686
0
 
LVL 41

Assisted Solution

by:ralmada
ralmada earned 300 total points
ID: 24079824
You can try something like this:
SELECT  CASE WHEN isnull(Table_Name) = 1
 THEN 'Not Exists'
 ELSE 'Exists' END
FROM INFORMATION_SCHEMA.TABLES
where TABLE_NAME = 'Data_0409'
or

select  case when a.ftable = 0
 then 'Not Exists'
 else 'Exists' end
from (SELECT count(Table_NAme) as ftable
FROM INFORMATION_SCHEMA.TABLES
where TABLE_NAME = 'Data_0409' group by Table_Name) a
And if you want to put that information in your @i variable then  
SELECT  @i = CASE WHEN isnull(Table_Name) = 1
 THEN 'Not Exists'
 ELSE 'Exists' END
FROM INFORMATION_SCHEMA.TABLES
where TABLE_NAME = 'Data_0409'  
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 

Author Comment

by:danny1620
ID: 24080116
Hi
@Pedro: I have been trying the samething as I mentioned before.. but dont know why am i getting that Error..
0
 

Author Comment

by:danny1620
ID: 24080317
Hi Ralmada
Thanks for your suggestion and i have tried which works fine and gives me the count when i use the basic Select statement Below and  map ftable to Variablename in the result set with single row but it gives me error when i try to use any of the other queries
SELECT count(Table_NAme) as ftable
FROM INFORMATION_SCHEMA.TABLES
where TABLE_NAME = 'Data_0409' group by Table_Name
Thanks
0
 
LVL 41

Expert Comment

by:ralmada
ID: 24080326
1) Have you tried any of my suggestions?
2) you need to add a length to @i, so when you declare it it should be something like declare @i varchar(10) or the length you want.
0
 
LVL 41

Expert Comment

by:ralmada
ID: 24080415
Another option could be:
select CASE WHEN isnull(
SELECT top 1
FROM INFORMATION_SCHEMA.TABLES
where TABLE_NAME = 'Data_0409' group by Table_Name
) = 1 then 'Not Exists'
else 'Exists' end  
0
 

Author Comment

by:danny1620
ID: 24080460
Hey thanks ralmada for reminding me that.. It works fine... But before I close the question i want another suggestion from you guys...
I am actually trying to check the table existence (3 tables in 3 different DB's) and if they all exist take presnt month or else they would take last months date... what would you guys think is the best way to do this in the package this would be the Start of the package....
Thanks
0
 

Author Comment

by:danny1620
ID: 24080476
Hi Pedro...
The link you sent me sure did work.. Thanks a lot
I am actually trying to check the table existence (3 tables in 3 different DB's) and if they all exist take presnt month or else they would take last months date... what would you guys think is the best way to do this in the package this would be the Start of the package....
Thanks
0
 

Author Comment

by:danny1620
ID: 24080490
Guys
i would like your suggestions .. Its Ok even if you dnt .. I am going to divide the points equally ..
Thanks a lot guysss
0
 

Author Comment

by:danny1620
ID: 24080593
Will the same SQL statements with a union to different databases work??? Help me out
0
 
LVL 41

Expert Comment

by:ralmada
ID: 24080708
yes, you can combine resulsets from three databases using union, provided the subqueries return the same columns.

select ... from databasename1.INFORMATION_SCHEMA.TABLES 
where ...
UNION ALL
select ... from databasename2.INFORMATION_SCHEMA.TABLES 
where ...
UNION ALL
select ... from databasename3.INFORMATION_SCHEMA.TABLES 
where ...

Open in new window

0
 

Author Comment

by:danny1620
ID: 24081121
hi ralmada,
Correct me if i am wrong.. I tried to union all the sQL statements and store the full result set value in a Object Type variable which looks like as below in Management Studio
ColumnName
  • Exists
  • Exists
  • Exists
Now assuming that they are stored the same way in the variable also how do i proceed and check if all the values in the table  are 'Exist' and change my date variable..
0
 
LVL 41

Expert Comment

by:ralmada
ID: 24081388
This will tell you the counts of your columnname for those that are called 'Exists'. You can store that value in a variable. If = 3 then it means the table in question exists in all three databases.

select count(ColumnName) from (
select ... from databasename1.INFORMATION_SCHEMA.TABLES 
where ...
UNION ALL
select ... from databasename2.INFORMATION_SCHEMA.TABLES 
where ...
UNION ALL
select ... from databasename3.INFORMATION_SCHEMA.TABLES 
where ...
) b
where ColumnName = 'Exists'
group by ColumnName

Open in new window

0
 

Author Comment

by:danny1620
ID: 24081514
Hi Ralmada ,
Sorry to bother you ... But last fix ... Below is the query which i am trying to Execute but get an error saying ------- No column was specified for column 1 of 'b'

select count(b.ColumnName) from
(select case when X.Ftable = 0
then 'Not Exists'
else 'Exists' end
from (SELECT count(Table_Name) as Ftable
FROM [****].[INFORMATION_SCHEMA].[TABLES]
where TABLE_NAME = 'Data_0409' group by Table_Name) X
Union ALL
select case when Y.Ftable = 0
then 'Not Exists'
else 'Exists' end
from (SELECT count(Table_NAme) as Ftable
FROM [****].[INFORMATION_SCHEMA].[TABLES]
where TABLE_NAME = 'Data_0409' group by Table_Name) Y
UNION ALL
select case when Z.Ftable = 0
then 'Not Exists'
else 'Exists' end
from (SELECT count(Table_NAme) as Ftable
FROM [****].[INFORMATION_SCHEMA].[TABLES]
where TABLE_NAME = 'Data_0409' group by Table_Name) Z)
b
where ColumnName = 'Exists'
group by ColumnName
0
 
LVL 41

Assisted Solution

by:ralmada
ralmada earned 300 total points
ID: 24081555
Need to define column name in each subquery  :-)
(Change it for a name that suits your need).

select count(b.ColumnName) from 
(select case when X.Ftable = 0 
then 'Not Exists' 
else 'Exists' end as ColumnName
from (SELECT count(Table_Name) as Ftable 
FROM [****].[INFORMATION_SCHEMA].[TABLES] 
where TABLE_NAME = 'Data_0409' group by Table_Name) X 
Union ALL 
select case when Y.Ftable = 0 
then 'Not Exists' 
else 'Exists' end  as ColumnName 
from (SELECT count(Table_NAme) as Ftable 
FROM [****].[INFORMATION_SCHEMA].[TABLES] 
where TABLE_NAME = 'Data_0409' group by Table_Name) Y 
UNION ALL 
select case when Z.Ftable = 0 
then 'Not Exists' 
else 'Exists' end  as ColumnName
from (SELECT count(Table_NAme) as Ftable 
FROM [****].[INFORMATION_SCHEMA].[TABLES] 
where TABLE_NAME = 'Data_0409' group by Table_Name) Z) 
b 
where ColumnName = 'Exists' 
group by ColumnName

Open in new window

0
 

Author Closing Comment

by:danny1620
ID: 31567136
Thanks a Lot Ralmada and Pedro...
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question