TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Danish Habib
NA
694
244k
adding two queries in sql server
Aug 25 2015 7:40 AM
I have two queries and i am listing them below make a single query from them if any one can do
First Query:"
SELECT sum(cte.TARGET) "target" , sum(cte.ACHIEVED) "achieved" FROM (SELECT sum(DISTINCT( F.TargetValue+F.Target_ForMen)) AS TARGET ,sum(S.Achieved) AS ACHIEVED FROM QuestionTarget F
LEFT OUTER JOIN AnswersNew AS S ON S.Question_ID=F.Question_ID
GROUP BY F.Question_ID
)cte
"
Second Query:"
SELECT
QT.QuestionTarget As Target,QT.Question_ID,Q.QuestionText,AN.QTotal As Achieved,QT.QT_ForWomen AS TW,AN.id,QT.QT_FormMen AS TM,AN.QT_ForMen AS AM,AN.QT_ForWomen AS AW,QT.QT_ForGirl AS TG,AN.QT_ForGirl AS AG,QT.QT_ForBoy AS TB,AN.QT_ForBoy AS AB,V.VillageName,AN.CdfPErsonName,QT.District,AN.Year,
AN.Quarter,D.DistrictName ,QU.Quarter_Name,CC.CommunityCodeName,G.Group_Name,Y.Year_Name,AN.Date_Created,
AN.UserTypes,AN.AnswerID,U.IsActive,AN.Status from AnswersNew AN
INNER JOIN QuestionTarget QT ON QT.Question_ID= AN.Question_ID AND QT.Year=AN.Year AND QT.Quarter=AN.Quarter AND AN.DistrictId=QT.District
INNER JOIN Villages V ON V.VlgID=AN.VillagesId
INNER JOIN Quarter Qu ON Qu.Quarter_ID=AN.Quarter
INNER JOIN Users U ON U.UserId=AN.CDF_ID
INNER JOIN Questions Q ON Q.QuestionIds=QT.Question_ID
INNER JOIN CommunityCodes CC ON CC.CommunityCodeID =AN.CommunityCodes
INNER JOIN Groups G ON G.Group_ID=AN.UserTypes
INNER JOIN Year Y ON Y.YEAR_ID=AN.Year
INNER JOIN Districts D on D.DistrictId=U.DistrictId
WHERE U.IsVisible = 1
"
Reply
Answers (
2
)
please explain how to do sql scheduling
Invalid column ID in my sql query