Click here to Skip to main content
15,306,017 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
The below statement suppose to show the ads which is equal cookie Location and that is working but the condition approv its not working as all user whose have value into approv column Y or N their ads is appear where should only users whith Y value appears i tried also to change from
WHERE IUS.[approv]='Y'
to
And IUS.[approv]='Y'
but the problem still exist

SQL
string HPAdsFQuery = @"SELECT AD.[AdsID], AD.[Country], AD.[State], AD.[City], AD.[AdsTit], SUBSTRING([AD.AdsDesc],1,50) as AD.AdsDesc,
            AD.[AdsPrice], AD.[Section], AD.[Category], AD.[Img1], AD.[AdsDate], IUS.[approv] FROM [ads] as AD JOIN UserInfo as IUS ON  AD.[Country] = @Location WHERE IUS.[approv]='Y' ORDER BY AD.[AdsDate] DESC";
Posted
Comments
A. Orozco 10-Dec-15 15:52pm
   
Is there a particular reason you need to join [ads] and UserInfo tables? It looks like you JOIN condition is not exactly right.
Member 10690878 10-Dec-15 17:02pm
   
yes the both tables contain column called UID so what i am looking is from the statement is to check into UserInfo if the user has Y value then show the ads otherwise dont show

1 solution

When you join two tables together you have to specify which fields in both tables are participating in the join.

You haven't said which field in UserInfo should be joined to [AD]
   
Comments
Member 10690878 10-Dec-15 17:02pm
   
Hi @Duncan Edwards Jones yes the both tables contain column called UID so what i am looking is from the statement is to check into UserInfo if the user has Y value then show the ads otherwise dont show
Duncan Edwards Jones 10-Dec-15 18:23pm
   
Therefore

SELECT AD.[AdsID],
AD.[Country],
AD.[State],
AD.[City],
AD.[AdsTit],
SUBSTRING([AD.AdsDesc],1,50) as AdsDesc,
AD.[AdsPrice],
AD.[Section],
AD.[Category],
AD.[Img1],
AD.[AdsDate],
IUS.[approv]
FROM [ads] as AD JOIN UserInfo as IUS
ON AD.UID = IUS.UID
WHERE AD.[Country] = @Location
AND IUS.[approv]='Y'
ORDER BY AD.[AdsDate] DESC";
phil.o 10-Dec-15 19:40pm
   
That would make a perfect solution :)
Member 10690878 11-Dec-15 9:41am
   
Thanks for your reply, but the code showing error message Incorrect syntax near '.'.
Duncan Edwards Jones 11-Dec-15 15:08pm
   
edited as above.
(You can't include a table name in an alias...) therefore "As [AD].AdsDesc " is not allowed.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900