Question : MSSQL need to add output field to an advanced query

this query works fine - but I want to add a field to it's output. If you look in the text_modalities table, in addition to the article_id, there is also a page_identity_id column. Essentially, I am using this number to pass on to another query that is controlled by the output of this one. I thought that I could just tack on the column to the select from list, but is appears to be breaking the code. I am not sure why - I get confused easily with more advanced queries like this one.




SELECT article_date as update_date, article_title as update_title, created_by as ministry_leader,
            ministry_desc, article_id, mission_statement, author_name,
            (SELECT rtrim(first_name) + ' ' + rtrim(last_name) from users where user_id = created_by) as u_by,
            file_content1, file_content2, file_content3
      FROM text_modalities, ministries
      WHERE text_modalities.ministrY_id = ministries.ministry_id
      AND ministries.ministry_id = 141
      AND text_modalities.article_type = 'M'
aND article_id = (SELECT max(article_id) FROM text_modalities x WHERE article_type = 'M'
            AND x.ministry_id = ministries.ministry_id AND article_date = (SELECT max(article_date)
            FROM text_modalities y WHERE article_type = 'M' AND Y.ministry_id = ministries.ministry_id))      
Attachments:
 
table for ministries
 
 
table for text_modalties
 
 
table for text_modalities
 
 
table for users
 

Answer : MSSQL need to add output field to an advanced query

Something like this:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
SELECT text_modalities.page_identity_id, article_date as update_date, article_title as update_title, created_by as ministry_leader, 
            ministry_desc, article_id, mission_statement, author_name,
            (SELECT rtrim(first_name) + ' ' + rtrim(last_name) from users where user_id = created_by) as u_by, 
            file_content1, file_content2, file_content3
      FROM text_modalities, ministries
      WHERE text_modalities.ministrY_id = ministries.ministry_id
      AND ministries.ministry_id = 141
      AND text_modalities.article_type = 'M'
aND article_id = (SELECT max(article_id) FROM text_modalities x WHERE article_type = 'M'
            AND x.ministry_id = ministries.ministry_id AND article_date = (SELECT max(article_date) 
            FROM text_modalities y WHERE article_type = 'M' AND Y.ministry_id = ministries.ministry_id))  
Random Solutions  
 
programming4us programming4us