Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Query to pull data from 2 different tables

Author  Topic 

potn1
Starting Member

33 Posts

Posted - 2009-09-17 : 12:08:21
Hi so currently I am using VS2008 and am using a DNN module to pull information based on a specific Article on our website. On the home page I am currently displaying the Title, Summary, Date and Author of the article. Currently under our feature Stories section of the site http://prepsonthenet.com/dnn/Home/tabid/386/Default.aspx the Title, Summary and Date, Author are being displayed for the top 8 articles that contain images. I was able to combine the 'Author' and Article table to display the 'AuthorName' for the first 8 images. That code is below:


strQueryArticleFirst.Append("select top 4 ArticleID,Title,Summary,[Text],");
strQueryArticleFirst.Append("(SELECT NAME FROM AUTHOR AU WHERE AU.AUTHORID = Article.AUTHORID) AS AUTHORNAME, ");
strQueryArticleFirst.Append("Convert(varchar(50),date,110)as [Date] from article");
strQueryArticleFirst.Append(" WHERE CategoryID=27 AND State='WI' AND deleted is null ");


Within this we have a strQueryArticleSecond which displays the next 6 stories without images: http://prepsonthenet.com/dnn/Home/tabid/386/Default.aspx

The code is a bit different here though and I can't seem to figure out how to link this back up to grab the 'AuthorName'


strQueryArticleSecond.Append("SELECT * FROM(");
strQueryArticleSecond.Append("select top 4 * from( ");
strQueryArticleSecond.Append("select top 8 * from article ");
strQueryArticleSecond.Append("where CategoryID=27 AND State='WI' and deleted is null ");


I get what the strQueryArticleSecond and how it is grabbing all the fields that were used in strQueryArticleFirst. I am just wondering how to re-link the AuthorName is this strQueryArticleSecond. Any help is appreciated. Thanks!

potn1
Starting Member

33 Posts

Posted - 2009-09-18 : 10:43:27
anyone have any idea?
Go to Top of Page

potn1
Starting Member

33 Posts

Posted - 2009-09-18 : 14:23:23
A friend suggested this to me but still no luck...

strQueryArticleSecond.Append("SELECT top 4, top 8,");
strQueryArticleSecond.Append("(SELECT NAME FROM AUTHOR AU WHERE AU.AUTHORID = Article.AUTHORID) AS AUTHORNAME");
strQueryArticleSecond.Append("from article ");
strQueryArticleSecond.Append("where CategoryID=27 AND State='WI' and deleted is null ");
Go to Top of Page
   

- Advertisement -