Solved

Execute SQL Task Result Set Error

Posted on 2009-04-06
17
2,413 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
Comment Utility
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
Comment Utility
0
 
LVL 41

Assisted Solution

by:ralmada
ralmada earned 300 total points
Comment Utility
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
 

Author Comment

by:danny1620
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

 

Author Comment

by:danny1620
Comment Utility
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
Comment Utility
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
Comment Utility
Will the same SQL statements with a union to different databases work??? Help me out
0
 
LVL 41

Expert Comment

by:ralmada
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks a Lot Ralmada and Pedro...
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
In this article I will describe the Copy Database Wizard 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.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now