How to set condition to UNION ALL Query

Posted by Navalemanoj0405 under Sql Server on 3/25/2011 | Points: 10 | Views : 2895 | Status : [Member] | Replies : 1
Dear All,
Below is my SQL query in which I have used UNION All In my outer query. so I want to select data onwards particular date . Is it possible? if yes please reply.
(if you are not getting my question plz revert me)

--------------------------------------------------------------------------------------------------
--KNOW-HOWS
-------------------
SELECT KnowHowID AS Id,
FirstName + ' '+ LastName AS PostedBY,--PostedByID
Title AS Title,
ImagePath AS PhotoGraph,
PostedDateTime AS DateTime,
'knowHows' AS FeatureName,
'' AS cnt
FROM uvw_KnowHows
WHERE Active=1 AND PostedByID IN( --This query is for all friend of this user
SELECT FriendID
FROM tblFriends
WHERE UserID=422973513 AND ISApproved = 1
UNION ALL
SELECT UserID
FROM tblFriends
WHERE FriendID =422973513 AND ISApproved = 1
UNION ALL
--This query is for All members in common network with this user
SELECT FK_UserID
FROM tblNetworkMembers
WHERE FK_NetworkId IN (
SELECT FK_NetworkId
FROM tblNetworkMembers
WHERE FK_UserID=422973513
)
)
UNION All
---------------------------------------------------------------------------------------------------------------------
--NEWS-VIEWS
-------------------
SELECT NewsViewsID AS Id,
FirstName + ' '+ LastName AS PostedBy,
Title AS Title,
ImagePath AS PhotoGraph,
PostedDateTime AS DateTime,
'NewsViews' AS FeatureName,
'' AS cnt
FROM uvw_NewsViews
WHERE Active=1 AND PostedByID IN(
--This query is for all friend of this user
SELECT FriendID
FROM tblFriends
WHERE UserID=422973513 AND ISApproved = 1
UNION ALL
SELECT UserID
FROM tblFriends
WHERE FriendID =422973513 AND ISApproved = 1
UNION ALL
--This query is for All members in common network with this user
SELECT FK_UserID
FROM tblNetworkMembers
WHERE FK_NetworkId IN (
SELECT FK_NetworkId
FROM tblNetworkMembers
WHERE FK_UserID=422973513
)
)
UNION All
---------------------------------------------------------------------------------------------------------------------
--PUBLIC IMAGE
-------------------
SELECT PhotographID AS Id,
FirstName + ' '+ LastName AS PostedBy,
Title AS Title,
[Path] AS PhotoGraph,
PostedDateTime AS DateTime,
'PublicImage' AS FeatureName ,
'' AS cnt
FROM uvw_PublicAlbum
WHERE Active=1 AND UserID IN (
--This query is for all friend of this user
SELECT FriendID
FROM tblFriends
WHERE UserID=422973513 AND ISApproved = 1
UNION ALL
SELECT UserID
FROM tblFriends
WHERE FriendID =422973513 AND ISApproved = 1
UNION ALL
--This query is for All members in common network with this user
SELECT FK_UserID
FROM tblNetworkMembers
WHERE FK_NetworkId IN (
SELECT FK_NetworkId
FROM tblNetworkMembers
WHERE FK_UserID=422973513
)
)





Responses

Posted by: Pavanandey on: 3/29/2011 [Member] Bronze | Points: 25

Up
0
Down
Hi,

the result what you got out of the query above insert into an temp table and do the required select operation on that temp table

Thanks
Pavan Kumar
Mark Answer if this fits the need

Navalemanoj0405, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response