Quantcast
Channel: SQL Server Integration Services forum
Viewing all articles
Browse latest Browse all 24688

Using Union in Execute SQL Task

$
0
0

I am using the following SQL statement in an Excute SQL Task:

declare @RespAreaSubAreaID int, @UserLevelID int, @SubmittedByUserID int, @RespAreaID int, @SubAreaID int
Set @RespAreaSubAreaID = ?
Set @SubmittedByUserID = ?
Set @UserLevelID = ?
set @RespAreaID = ?
set @SubAreaID = ?

select users.User_EmailAddress + ';' As CC
                  from users inner join UserLevelsNotificationFrequencys on users.user_Id = UserLevelsNotificationFrequencys.User_id
                  where UserLevelID =  @UserLevelID and RespAreaSubAreaID = @RespAreaSubAreaID and (NotificationFrequencyID = 4 and users.user_id <> @SubmittedByUserID)
            union
            select users.User_EmailAddress + ',' As CC
                  from users inner join UserLevelsNotificationFrequencys on users.user_Id = UserLevelsNotificationFrequencys.User_id
                  where UserLevelID = @UserLevelID and RespAreaSubAreaID = @RespAreaSubAreaID and (NotificationFrequencyID = 1)

 I have my parameter mapped correctly. My results set is set to xml because I want it all in one string to use as a variable named User:CC. On the Result Set tab the result name is 0 and the variable name is User:CC. When I run my package I am getting the error below. Can I not do a union query in the execute SQL task? I tried to not declare anything and just map to each of the variables that I am passing in the order that they are needed but that didn't work either. Thanks in advance for your help in this matter.

 [Execute SQL Task] Error: Executing the query "declare @RespAreaSubAreaID int, @NotificationID in..." failed with the following error: "Syntax error, permission violation, or other nonspecific error". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.


Reach for the unknown!


Viewing all articles
Browse latest Browse all 24688

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>